Submission #947628

#TimeUsernameProblemLanguageResultExecution timeMemory
947628ngchkhang_cvaJOIOJI (JOI14_joioji)C++17
0 / 100
1 ms604 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int n, I[200005], J[200005], O[200005], res = 0; string s; bool check(int x){ for(int i = 1;i <= n - x + 1;i++){ int a = O[i + x - 1] - O[i - 1]; int b = J[i + x - 1] - J[i - 1]; int c = I[i + x - 1] - I[i - 1]; if(a == b && b == c) return true; } return false; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin >> n; cin >> s; s = ' ' + s; for(int i = 1;i <= n;i++){ char x = s[i]; O[i] = O[i - 1]; J[i] = J[i - 1]; I[i] = I[i - 1]; if(x == 'I') I[i]++; if(x == 'J') J[i]++; if(x == 'O') O[i]++; } int l = 0, r = n / 3; while(r >= l){ int mid = (r + l) / 2; if(check(mid * 3)){ res = mid * 3; l = mid + 1; } else r = mid - 1; } cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...