Submission #119415

# Submission time Handle Problem Language Result Execution time Memory
119415 2019-06-21T08:03:49 Z popovicirobert Difference (POI11_roz) C++14
100 / 100
130 ms 1408 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], 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

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 time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 500 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 4 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 1368 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 78 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 1364 KB Output is correct
2 Correct 83 ms 1152 KB Output is correct
3 Correct 78 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 1360 KB Output is correct
2 Correct 81 ms 1364 KB Output is correct
3 Correct 82 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 1372 KB Output is correct
2 Correct 78 ms 1408 KB Output is correct
3 Correct 89 ms 1400 KB Output is correct