Submission #642601

# Submission time Handle Problem Language Result Execution time Memory
642601 2022-09-20T08:26:16 Z someone JOIOJI (JOI14_joioji) C++14
100 / 100
38 ms 7272 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 2e5 + 42, INF = 1e18 + 42;

int n, nb[3], val[N];
map<pair<int, int>, int> first;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    for(int i = 0; i < n; i++) {
        char c; cin >> c;
        if(c == 'O')
            val[i] = 1;
        else if(c == 'I')
            val[i] = 2;
    }
    int maxi = 0;
    first[{0, 0}] = -1;
    for(int i = 0; i < n; i++) {
        nb[val[i]]++;
        if(first.find({nb[1] - nb[0], nb[2] - nb[0]}) == first.end()) {
            first[{nb[1] - nb[0], nb[2] - nb[0]}] = i;
        } else {
            maxi = max(maxi, i - first[{nb[1] - nb[0], nb[2] - nb[0]}]);
        }
    }
    cout << maxi;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 8 ms 1104 KB Output is correct
3 Correct 10 ms 1748 KB Output is correct
4 Correct 19 ms 2892 KB Output is correct
5 Correct 30 ms 4468 KB Output is correct
6 Correct 38 ms 4872 KB Output is correct
7 Correct 38 ms 5456 KB Output is correct
8 Correct 38 ms 4768 KB Output is correct
9 Correct 38 ms 5088 KB Output is correct
10 Correct 36 ms 4928 KB Output is correct
11 Correct 29 ms 6336 KB Output is correct
12 Correct 22 ms 3540 KB Output is correct
13 Correct 21 ms 2952 KB Output is correct
14 Correct 32 ms 7272 KB Output is correct
15 Correct 25 ms 2668 KB Output is correct