Submission #119407

#TimeUsernameProblemLanguageResultExecution timeMemory
119407popovicirobertDifference (POI11_roz)C++14
30 / 100
106 ms2424 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], fr[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';

        for(int ch = 0; ch < 26; ch++) {
            if(fr[ch] == 0) {
                continue;
            }
            ans = max(ans, max(fr[str[i]] - fr[ch] - best[str[i]][ch], fr[ch] - fr[str[i]] - best[ch][str[i]]));
        }

        fr[str[i]]++;
        for(int ch = 0; ch < 26; ch++) {
            best[ch][str[i]] = min(best[ch][str[i]], fr[ch] - fr[str[i]]);
            best[str[i]][ch] = min(best[str[i]][ch], fr[str[i]] - fr[ch]);
        }
    }

    cout << ans;

    //cin.close();
    //cout.close();
    return 0;
}

Compilation message (stderr)

roz.cpp: In function 'int main()':
roz.cpp:40:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     cin >> n >> str + 1;
                 ~~~~^~~
roz.cpp:50:41: warning: array subscript has type 'char' [-Wchar-subscripts]
             ans = max(ans, max(fr[str[i]] - fr[ch] - best[str[i]][ch], fr[ch] - fr[str[i]] - best[ch][str[i]]));
                                         ^
roz.cpp:50:65: warning: array subscript has type 'char' [-Wchar-subscripts]
             ans = max(ans, max(fr[str[i]] - fr[ch] - best[str[i]][ch], fr[ch] - fr[str[i]] - best[ch][str[i]]));
                                                                 ^
roz.cpp:50:90: warning: array subscript has type 'char' [-Wchar-subscripts]
             ans = max(ans, max(fr[str[i]] - fr[ch] - best[str[i]][ch], fr[ch] - fr[str[i]] - best[ch][str[i]]));
                                                                                          ^
roz.cpp:50:109: warning: array subscript has type 'char' [-Wchar-subscripts]
             ans = max(ans, max(fr[str[i]] - fr[ch] - best[str[i]][ch], fr[ch] - fr[str[i]] - best[ch][str[i]]));
                                                                                                             ^
roz.cpp:53:18: warning: array subscript has type 'char' [-Wchar-subscripts]
         fr[str[i]]++;
                  ^
roz.cpp:55:28: warning: array subscript has type 'char' [-Wchar-subscripts]
             best[ch][str[i]] = min(best[ch][str[i]], fr[ch] - fr[str[i]]);
                            ^
roz.cpp:55:51: warning: array subscript has type 'char' [-Wchar-subscripts]
             best[ch][str[i]] = min(best[ch][str[i]], fr[ch] - fr[str[i]]);
                                                   ^
roz.cpp:55:72: warning: array subscript has type 'char' [-Wchar-subscripts]
             best[ch][str[i]] = min(best[ch][str[i]], fr[ch] - fr[str[i]]);
                                                                        ^
roz.cpp:56:24: warning: array subscript has type 'char' [-Wchar-subscripts]
             best[str[i]][ch] = min(best[str[i]][ch], fr[str[i]] - fr[ch]);
                        ^
roz.cpp:56:47: warning: array subscript has type 'char' [-Wchar-subscripts]
             best[str[i]][ch] = min(best[str[i]][ch], fr[str[i]] - fr[ch]);
                                               ^
roz.cpp:56:63: warning: array subscript has type 'char' [-Wchar-subscripts]
             best[str[i]][ch] = min(best[str[i]][ch], fr[str[i]] - fr[ch]);
                                                               ^
#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...