Submission #885105

#TimeUsernameProblemLanguageResultExecution timeMemory
885105haraoDifference (POI11_roz)C++17
100 / 100
136 ms12456 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e6 + 7; int n, pre[N], ans; string s; vector<int> g[26]; void solve (int m) { for(int i = 1;i <= n; i++) { pre[i] = pre[i - 1] + ((s[i] - 'a') == m); } for(int k = 0;k < 26; k++) { if(k == m) continue; int mn = 0; for(int i = 1;i < g[k].size(); i++) { ans = max(ans, pre[g[k][i]] - i - mn); mn = min(mn, pre[g[k][i-1]] - i); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen(".inp", "r", stdin); // freopen(".out", "w", stdout); cin >> n; cin >> s; s = " " + s; for(int i = 1;i <= n; i++) { g[s[i] - 'a'].push_back(i); } for(int i = 0;i < 26; i++) g[i].push_back(n); for(int i = 0;i < 26; i++) solve(i); cout << ans; }

Compilation message (stderr)

roz.cpp: In function 'void solve(int)':
roz.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   for(int i = 1;i < g[k].size(); i++) {
      |                 ~~^~~~~~~~~~~~~
#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...