# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
947722 | Volvox123 | JOIOJI (JOI14_joioji) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> counter;
int main()
{
int n;
cin >> n;
string poem;
cin >> poem;
int max_length = 0;
counter[0] = -1;
int diff = 0;
for (int i = 0; i < n; i++) {
if (poem[i] == 'J') {
diff++;
} else if (poem[i] == 'O') {
diff--;
}
if (counter.find(diff) != counter.end()) {
max_length = max(max_length, i - counter[diff]);
} else {
counter[diff] = i;
}
}
cout << max_length << endl;
return 0;
}