Submission #119415

#TimeUsernameProblemLanguageResultExecution timeMemory
119415popovicirobertDifference (POI11_roz)C++14
100 / 100
130 ms1408 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long // 217 // 44 /* const int MOD = ; inline void mod(int &x) { if(x >= MOD) x -= MOD; } inline void add(int &x, int y) { x += y; mod(x); } inline void mul(int &x, int y) { x = (1LL * x * y) % MOD; } */ using namespace std; const int MAXN = (int) 1e6; char str[MAXN + 1]; int best[26][26], pos[26][26]; int fr[26], last[26]; int main() { //ifstream cin("B.in"); //ofstream cout("B.out"); int i, n; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> str + 1; int ans = 0; for(i = 1; i <= n; i++) { str[i] -= 'a'; fr[str[i]]++, last[str[i]] = i; for(int ch = 0; ch < 26; ch++) { if(fr[ch] == 0) { continue; } ans = max(ans, fr[str[i]] - fr[ch] - best[str[i]][ch] - (last[ch] <= pos[str[i]][ch])); ans = max(ans, fr[ch] - fr[str[i]] - best[ch][str[i]] - (last[str[i]] <= pos[ch][str[i]])); } for(int ch = 0; ch < 26; ch++) { if(best[ch][str[i]] > fr[ch] - fr[str[i]]) { best[ch][str[i]] = fr[ch] - fr[str[i]]; pos[ch][str[i]] = i; } if(best[str[i]][ch] > fr[str[i]] - fr[ch]) { best[str[i]][ch] = fr[str[i]] - fr[ch]; pos[str[i]][ch] = i; } } } cout << ans; //cin.close(); //cout.close(); return 0; }

Compilation message (stderr)

roz.cpp: In function 'int main()':
roz.cpp:41:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     cin >> n >> str + 1;
                 ~~~~^~~
roz.cpp:46:18: warning: array subscript has type 'char' [-Wchar-subscripts]
         fr[str[i]]++, last[str[i]] = i;
                  ^
roz.cpp:46:34: warning: array subscript has type 'char' [-Wchar-subscripts]
         fr[str[i]]++, last[str[i]] = i;
                                  ^
roz.cpp:53:37: warning: array subscript has type 'char' [-Wchar-subscripts]
             ans = max(ans, fr[str[i]] - fr[ch] - best[str[i]][ch] - (last[ch] <= pos[str[i]][ch]));
                                     ^
roz.cpp:53:61: warning: array subscript has type 'char' [-Wchar-subscripts]
             ans = max(ans, fr[str[i]] - fr[ch] - best[str[i]][ch] - (last[ch] <= pos[str[i]][ch]));
                                                             ^
roz.cpp:53:92: warning: array subscript has type 'char' [-Wchar-subscripts]
             ans = max(ans, fr[str[i]] - fr[ch] - best[str[i]][ch] - (last[ch] <= pos[str[i]][ch]));
                                                                                            ^
roz.cpp:54:46: warning: array subscript has type 'char' [-Wchar-subscripts]
             ans = max(ans, fr[ch] - fr[str[i]] - best[ch][str[i]] - (last[str[i]] <= pos[ch][str[i]]));
                                              ^
roz.cpp:54:65: warning: array subscript has type 'char' [-Wchar-subscripts]
             ans = max(ans, fr[ch] - fr[str[i]] - best[ch][str[i]] - (last[str[i]] <= pos[ch][str[i]]));
                                                                 ^
roz.cpp:54:81: warning: array subscript has type 'char' [-Wchar-subscripts]
             ans = max(ans, fr[ch] - fr[str[i]] - best[ch][str[i]] - (last[str[i]] <= pos[ch][str[i]]));
                                                                                 ^
roz.cpp:54:100: warning: array subscript has type 'char' [-Wchar-subscripts]
             ans = max(ans, fr[ch] - fr[str[i]] - best[ch][str[i]] - (last[str[i]] <= pos[ch][str[i]]));
                                                                                                    ^
roz.cpp:59:31: warning: array subscript has type 'char' [-Wchar-subscripts]
             if(best[ch][str[i]] > fr[ch] - fr[str[i]]) {
                               ^
roz.cpp:59:53: warning: array subscript has type 'char' [-Wchar-subscripts]
             if(best[ch][str[i]] > fr[ch] - fr[str[i]]) {
                                                     ^
roz.cpp:60:32: warning: array subscript has type 'char' [-Wchar-subscripts]
                 best[ch][str[i]] = fr[ch] - fr[str[i]];
                                ^
roz.cpp:60:54: warning: array subscript has type 'char' [-Wchar-subscripts]
                 best[ch][str[i]] = fr[ch] - fr[str[i]];
                                                      ^
roz.cpp:61:31: warning: array subscript has type 'char' [-Wchar-subscripts]
                 pos[ch][str[i]] = i;
                               ^
roz.cpp:63:27: warning: array subscript has type 'char' [-Wchar-subscripts]
             if(best[str[i]][ch] > fr[str[i]] - fr[ch]) {
                           ^
roz.cpp:63:44: warning: array subscript has type 'char' [-Wchar-subscripts]
             if(best[str[i]][ch] > fr[str[i]] - fr[ch]) {
                                            ^
roz.cpp:64:28: warning: array subscript has type 'char' [-Wchar-subscripts]
                 best[str[i]][ch] = fr[str[i]] - fr[ch];
                            ^
roz.cpp:64:45: warning: array subscript has type 'char' [-Wchar-subscripts]
                 best[str[i]][ch] = fr[str[i]] - fr[ch];
                                             ^
roz.cpp:65:27: warning: array subscript has type 'char' [-Wchar-subscripts]
                 pos[str[i]][ch] = 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...