## #2327262

Solution for 0604: Take the 'IOI' train by olphe

Source Code Status Test Cases
Policy: public     Reviewed: 15
00.06 sec    34508 KB    62 lines     1436 bytes    2017-05-19 22:39
```#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

int N, M;
string S;
string T;
int dp[2002][2002][2];
int ans;

int main() {
ios::sync_with_stdio(false);
cin >> N >> M;
cin >> S;
cin >> T;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
dp[i][j][0] = -1;
dp[i][j][1] = -1;
}
}
reverse(S.begin(), S.end());
reverse(T.begin(), T.end());
//cout << S << endl;
//cout << T << endl;
S = '(' + S;
T = 'T' + T;
if (S[1] == 'I')dp[1][0][1] = 1;
if (T[1] == 'I')dp[0][1][1] = 1;
for (int i = 1; i < N + M; i++) {
for (int j = max(0, i - M); j <= min(i, N); j++) {
//	cout << i << " " << j << endl;
if (S[j + 1] == 'O')dp[j + 1][i - j][0] = max({ dp[j + 1][i - j][0], dp[j][i - j][1] + 1 ,0 });
else dp[j + 1][i - j][1] = max({ 1, dp[j + 1][i - j][1], dp[j][i - j][0] + 1 });
if (T[i - j + 1] == 'O')dp[j][i - j + 1][0] = max({ dp[j][i - j + 1][0], dp[j][i - j][1] + 1 ,0 });
else dp[j][i - j + 1][1] = max({ 1, dp[j][i - j + 1][1] ,dp[j][i - j][0] + 1 });
}
}
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= M; j++) {
ans = max(ans, dp[i][j][1]);
}
}
cout << ans << endl;
return 0;
}

```
 Compile Error Logs: You are not authorized to see the message.

Status
 Judge: 54/54 C++14 CPU: 00.06 sec Memory: 34508 KB Length: 1436 B 2017-05-19 22:39 2017-05-19 22:39
Results for testcases
 Case # Verdict CPU Time Memory In Out Case Name Case #1: : Accepted 00.00 sec 3244 KB Case #2: : Accepted 00.00 sec 3004 KB Case #3: : Accepted 00.00 sec 3140 KB Case #4: : Accepted 00.00 sec 3124 KB Case #5: : Accepted 00.00 sec 3056 KB Case #6: : Accepted 00.00 sec 3204 KB Case #7: : Accepted 00.00 sec 3232 KB Case #8: : Accepted 00.00 sec 3060 KB Case #9: : Accepted 00.00 sec 3148 KB Case #10: : Accepted 00.00 sec 3044 KB Case #11: : Accepted 00.00 sec 3040 KB Case #12: : Accepted 00.00 sec 3304 KB Case #13: : Accepted 00.00 sec 3388 KB Case #14: : Accepted 00.00 sec 3216 KB Case #15: : Accepted 00.00 sec 3188 KB Case #16: : Accepted 00.00 sec 3412 KB Case #17: : Accepted 00.00 sec 3376 KB Case #18: : Accepted 00.00 sec 3380 KB Case #19: : Accepted 00.00 sec 3380 KB Case #20: : Accepted 00.00 sec 3424 KB Case #21: : Accepted 00.00 sec 3284 KB Case #22: : Accepted 00.05 sec 34508 KB Case #23: : Accepted 00.05 sec 34424 KB Case #24: : Accepted 00.00 sec 13092 KB Case #25: : Accepted 00.05 sec 34440 KB Case #26: : Accepted 00.04 sec 34488 KB Case #27: : Accepted 00.04 sec 34336 KB Case #28: : Accepted 00.05 sec 34388 KB Case #29: : Accepted 00.05 sec 34388 KB Case #30: : Accepted 00.03 sec 34400 KB Case #31: : Accepted 00.04 sec 33960 KB Case #32: : Accepted 00.04 sec 34416 KB Case #33: : Accepted 00.04 sec 34484 KB Case #34: : Accepted 00.04 sec 34336 KB Case #35: : Accepted 00.04 sec 34476 KB Case #36: : Accepted 00.04 sec 34508 KB Case #37: : Accepted 00.04 sec 34460 KB Case #38: : Accepted 00.03 sec 34472 KB Case #39: : Accepted 00.06 sec 34320 KB Case #40: : Accepted 00.05 sec 34424 KB Case #41: : Accepted 00.00 sec 6428 KB Case #42: : Accepted 00.06 sec 34316 KB Case #43: : Accepted 00.04 sec 34412 KB Case #44: : Accepted 00.05 sec 34336 KB Case #45: : Accepted 00.05 sec 34476 KB Case #46: : Accepted 00.05 sec 34388 KB Case #47: : Accepted 00.04 sec 34476 KB Case #48: : Accepted 00.05 sec 33952 KB Case #49: : Accepted 00.04 sec 34504 KB Case #50: : Accepted 00.04 sec 34368 KB Case #51: : Accepted 00.04 sec 34460 KB Case #52: : Accepted 00.04 sec 34416 KB Case #53: : Accepted 00.04 sec 34428 KB Case #54: : Accepted 00.04 sec 34320 KB
 < prev | / | next >

 Judge Input #  ( | ) Judge Output #  ( | )