Submission #115794

#TimeUsernameProblemLanguageResultExecution timeMemory
115794choikiwonJOIOJI (JOI14_joioji)C++17
100 / 100
52 ms6280 KiB
#include<bits/stdc++.h> using namespace std; int N; string S; int f(char x) { if(x == 'J') return 0; if(x == 'O') return 1; if(x == 'I') return 2; } struct node { int a, b, c; bool operator <(const node &i) const { if(a != i.a) return a < i.a; if(b != i.b) return b < i.b; if(c != i.c) return c < i.c; return false; } }; int cnt[3]; map<node, int> chk; int main() { cin >> N >> S; int ans = 0; chk[ {0, 0, 0} ] = -1; for(int i = 0; i < N; i++) { cnt[ f(S[i]) ]++; int mn = min(cnt[0], min(cnt[1], cnt[2])); if(chk.find({ cnt[0] - mn, cnt[1] - mn, cnt[2] - mn }) != chk.end()) { ans = max(ans, i - chk[ { cnt[0] - mn, cnt[1] - mn, cnt[2] - mn } ]); } else chk[ { cnt[0] - mn, cnt[1] - mn, cnt[2] - mn } ] = i; } cout << ans; }

Compilation message (stderr)

joioji.cpp: In function 'int f(char)':
joioji.cpp:11:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...