# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
156109 | karma | JOIOJI (JOI14_joioji) | C++14 | 45 ms | 6216 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FileName "test"
#define ll long long
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ord_set;
typedef pair<int, int> pii;
const int N = int(1e3) + 2;
int n, curi, curj, curo, res = 0;
pii cur;
string s;
map<pii, int> mmap;
void Enter() {
cin >> n >> s; curi = curj = curo = 0;
cur = mp(0, 0); mmap[cur] = -1;
for(int i = 0; i < n; ++i) {
if(s[i] == 'O') ++curo;
else if(s[i] == 'J') ++curj;
else ++curi;
cur = mp(curo - curi, curj - curo);
if(mmap.count(cur)) {
res = max(res, i - mmap[cur]);
//cout << mmap[cur] << ' ' << i << '\n';
} else mmap[cur] = i;
}
cout << res;
}
void Solve() {
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen(FileName".inp", "r")) {
freopen(FileName".inp", "r", stdin);
freopen(FileName".out", "w", stdout);
}
Enter(), Solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |