Submission #119407

# Submission time Handle Problem Language Result Execution time Memory
119407 2019-06-21T07:51:55 Z popovicirobert Difference (POI11_roz) C++14
30 / 100
106 ms 2424 KB
#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

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 time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Incorrect 2 ms 396 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 512 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 2360 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 67 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 2364 KB Output is correct
2 Correct 80 ms 2040 KB Output is correct
3 Correct 65 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 2424 KB Output is correct
2 Correct 68 ms 2304 KB Output is correct
3 Incorrect 75 ms 2304 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 2424 KB Output is correct
2 Correct 67 ms 2352 KB Output is correct
3 Correct 76 ms 2304 KB Output is correct