Submission #30082

#TimeUsernameProblemLanguageResultExecution timeMemory
30082khsoo01Difference (POI11_roz)C++11
100 / 100
206 ms14332 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1000005; int n, sum[N], ans; char ipt[N]; vector<int> s[26]; void solve (int I) { for(int i=1;i<=n;i++) { sum[i] = sum[i-1] + (ipt[i] == I); } for(int k=0;k<26;k++) { if(k == I) continue; int mn = 0; for(int i=1;i<s[k].size();i++) { ans = max(ans, sum[s[k][i]] - i - mn); mn = min(mn, sum[s[k][i-1]] - i); } } } int main() { scanf("%d%s",&n,ipt+1); for(int i=1;i<=n;i++) { ipt[i] -= 'a'; s[ipt[i]].push_back(i); } for(int i=0;i<26;i++) s[i].push_back(n); for(int i=0;i<26;i++) solve(i); printf("%d\n",ans); }

Compilation message (stderr)

roz.cpp: In function 'void solve(int)':
roz.cpp:17:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=1;i<s[k].size();i++) {
                ^
roz.cpp: In function 'int main()':
roz.cpp:29:11: warning: array subscript has type 'char' [-Wchar-subscripts]
   s[ipt[i]].push_back(i);
           ^
roz.cpp:26:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%s",&n,ipt+1);
                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...