답안 #871619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871619 2023-11-11T07:54:02 Z vjudge1 Difference (POI11_roz) C++17
100 / 100
569 ms 13184 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) {
      |                            ~~^~~~~~~~~~
# 결과 실행 시간 메모리 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
4 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 1116 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 4 ms 568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 566 ms 8016 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 333 ms 6932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 566 ms 7760 KB Output is correct
2 Correct 431 ms 6912 KB Output is correct
3 Correct 184 ms 5868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 566 ms 8000 KB Output is correct
2 Correct 210 ms 10772 KB Output is correct
3 Correct 170 ms 8040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 569 ms 7804 KB Output is correct
2 Correct 232 ms 13184 KB Output is correct
3 Correct 181 ms 7244 KB Output is correct