Submission #156043

#TimeUsernameProblemLanguageResultExecution timeMemory
156043manh9203JOIOJI (JOI14_joioji)C++17
100 / 100
49 ms7916 KiB
#include<bits/stdc++.h> using namespace std; const long long base = 311; const long long mod = 1311322777; const int N = 2e5 + 5; int n,sum[N][3],ans; map<pair<int,int>,int> check; string s; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> s; s = " " + s; for(int i=1;i<=n;i++){ sum[i][1] = sum[i-1][1]; if(s[i] == 'J') sum[i][1]++; sum[i][2] = sum[i-1][2]; if(s[i] == 'O') sum[i][2]++; sum[i][3] = sum[i-1][3]; if(s[i] == 'I') sum[i][3]++; if(sum[i][1] == sum[i][2] && sum[i][2] == sum[i][3]){ ans = max(ans, i); } pair<int,int> tmp = {sum[i][2]-sum[i][1], sum[i][3]-sum[i][2]}; if(check[tmp] == 0){ check[tmp] = i; }else{ ans = max(ans, i-check[tmp]); } } cout << ans; }

Compilation message (stderr)

joioji.cpp: In function 'int main()':
joioji.cpp:16:25: warning: array subscript is above array bounds [-Warray-bounds]
   sum[i][3] = sum[i-1][3]; if(s[i] == 'I') sum[i][3]++;
               ~~~~~~~~~~^
joioji.cpp:16:11: warning: array subscript is above array bounds [-Warray-bounds]
   sum[i][3] = sum[i-1][3]; if(s[i] == 'I') sum[i][3]++;
   ~~~~~~~~^
joioji.cpp:16:52: warning: array subscript is above array bounds [-Warray-bounds]
   sum[i][3] = sum[i-1][3]; if(s[i] == 'I') sum[i][3]++;
                                            ~~~~~~~~^
joioji.cpp:17:53: warning: array subscript is above array bounds [-Warray-bounds]
   if(sum[i][1] == sum[i][2] && sum[i][2] == sum[i][3]){
                                             ~~~~~~~~^
joioji.cpp:20:53: warning: array subscript is above array bounds [-Warray-bounds]
   pair<int,int> tmp = {sum[i][2]-sum[i][1], sum[i][3]-sum[i][2]};
                                             ~~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...