Submission #1103916

# Submission time Handle Problem Language Result Execution time Memory
1103916 2024-10-22T08:44:11 Z ShadowShark Difference (POI11_roz) C++17
100 / 100
66 ms 2540 KB
#include <bits/stdc++.h>
using namespace std;

int sum[26][26], mn[26][26], cont[26][26];
/// define: array[first_char][second_char]: if first_char = 1 and second_char = -1;
/// mn: largest containing the second_char
/// cont: save the sum of the previous position before the second_char appear

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;
    cin >> n;

    string s;
    cin >> s;

    for (int i = 0; i < 26; i++)
        for (int j = 0; j < 26; j++)
            mn[i][j] = 1e9;

    int ans = 0;
    for (auto ch: s) {
        int x = ch - 'a';
        for (int y = 0; y < 26; y++) {
            if (x == y) continue;
            sum[x][y]++;
            ans = max(ans, sum[x][y] - mn[x][y]);

            sum[y][x]--;
            mn[y][x] = min(mn[y][x], cont[y][x]);
            cont[y][x] = sum[y][x];
            ans = max(ans, sum[y][x] - mn[y][x]);
        }
    }

    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 472 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 588 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 2540 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 44 ms 2276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 2540 KB Output is correct
2 Correct 43 ms 2276 KB Output is correct
3 Correct 40 ms 2276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 2540 KB Output is correct
2 Correct 53 ms 2456 KB Output is correct
3 Correct 47 ms 2540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 2540 KB Output is correct
2 Correct 49 ms 2540 KB Output is correct
3 Correct 62 ms 2540 KB Output is correct