Submission #947628

# Submission time Handle Problem Language Result Execution time Memory
947628 2024-03-16T16:43:22 Z ngchkhang_cva JOIOJI (JOI14_joioji) C++17
0 / 100
1 ms 604 KB
#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 time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -