답안 #849511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849511 2023-09-14T21:08:16 Z myst6 JOIOJI (JOI14_joioji) C++14
100 / 100
25 ms 5352 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  // one table of J-O
  // one table of O-I
  int ans = 0;
  vector<int> JO(N+1), OI(N+1);
  int j = 0, o = 0, i = 0, idx = 0;
  for (char c : s) {
    if (c == 'J') j++;
    if (c == 'O') o++;
    if (c == 'I') i++;
    idx++;
    JO[idx] = j-o;
    OI[idx] = o-i;
  }
  map<int,vector<int>> runs;
  for (int i=0; i<=N; i++) {
    runs[JO[i]].push_back(i);
  }
  for (const pair<int,vector<int>> &p : runs) {
    const vector<int> &v = p.second;
    map<int,int> fi;
    for (int i : v) {
      if (fi.count(OI[i])) {
        ans = max(ans, i - fi[OI[i]]);
      } else {
        fi[OI[i]] = i;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 4 ms 856 KB Output is correct
3 Correct 6 ms 1112 KB Output is correct
4 Correct 11 ms 1880 KB Output is correct
5 Correct 17 ms 2792 KB Output is correct
6 Correct 24 ms 3560 KB Output is correct
7 Correct 23 ms 3564 KB Output is correct
8 Correct 25 ms 3560 KB Output is correct
9 Correct 24 ms 3560 KB Output is correct
10 Correct 22 ms 3560 KB Output is correct
11 Correct 20 ms 5096 KB Output is correct
12 Correct 18 ms 3940 KB Output is correct
13 Correct 14 ms 3636 KB Output is correct
14 Correct 25 ms 5352 KB Output is correct
15 Correct 13 ms 3816 KB Output is correct