Submission #871613

# Submission time Handle Problem Language Result Execution time Memory
871613 2023-11-11T07:45:36 Z vjudge1 Difference (POI11_roz) C++17
90 / 100
582 ms 14228 KB
#include <bits/stdc++.h>

using namespace std;

const int oo = (int)1e9 + 7;

int main() {
    int n; cin >> n;
    string s; cin >> s;

    vector<vector<int>> pos(26, vector<int>());
    for(int i = 0; i < n; ++i) {
        pos[s[i] - 'a'].push_back(i);
    }

    int ans = 0;
    for(int c1 = 0; c1 < 26; ++c1) {
        for(int c2 = 0; c2 < 26; ++c2) {
            if (c1 == c2) continue;

            vector<int> p(pos[c1].size() + pos[c2].size());
            merge(pos[c1].begin(), pos[c1].end(), pos[c2].begin(), pos[c2].end(), p.begin());

            // printf("c1, c2: %d %d\n", c1, c2);
            // for(int i: p) printf("%d ", i);
            // puts("");

            vector<int> a(p.size());
            for(int i = 0; i < p.size(); ++i) {
                a[i] = (s[p[i]] - 'a' == c1) ? 1 : -1;
            }

            int sumI = 0, sumJ = 0, minF = oo;
            int j = 0;

            for(int i = 0; i < p.size(); ++i) {
                sumI += a[i];
                if (a[i] == -1) {
                    while (j < i) {
                        minF = min(minF, sumJ);
                        sumJ += a[j++];
                    }
                }
                ans = max(ans, sumI - minF);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Compilation message

roz.cpp: In function 'int main()':
roz.cpp:29:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |             for(int i = 0; i < p.size(); ++i) {
      |                            ~~^~~~~~~~~~
roz.cpp:36:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             for(int i = 0; i < p.size(); ++i) {
      |                            ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 1196 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 582 ms 9172 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 570 ms 9088 KB Output is correct
2 Correct 430 ms 7700 KB Output is correct
3 Correct 195 ms 6704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 567 ms 8856 KB Output is correct
2 Correct 216 ms 11844 KB Output is correct
3 Correct 166 ms 8388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 579 ms 8788 KB Output is correct
2 Correct 251 ms 14228 KB Output is correct
3 Correct 184 ms 8272 KB Output is correct