답안 #871668

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871668 2023-11-11T08:49:28 Z vjudge1 Difference (POI11_roz) C++17
100 / 100
756 ms 26088 KB
#include "bits/stdc++.h"
#define ii pair <int, int>
#define F first
#define S second
using namespace std;
const int N = 1e6+5;
int n;
char a[N];
int pre[N];
vector <int> save[30];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> n;
    for (int i = 1 ; i <= n ; i++) {
        cin >> a[i];
        save[a[i]-'a'].push_back(i);
    }
    int res = 0;
    for (int c1 = 0 ; c1 < 26 ; c1++)
        for (int c2 = 0 ; c2 < 26 ; c2++) {
            if (c1 == c2) continue;
            vector <ii> pos;
            pos.push_back(ii(0, 0));
            int pos1 = 0, pos2 = 0;
            while(pos1 < save[c1].size() || pos2 < save[c2].size()) {
                if (pos1 == save[c1].size()) {
                    pos.push_back(ii(save[c2][pos2], -1));
                    pos2++;
                    continue;
                }
                if (pos2 == save[c2].size()) {
                    pos.push_back(ii(save[c1][pos1], 1));
                    pos1++;
                    continue;
                }
                if (save[c1][pos1] < save[c2][pos2]) {
                    pos.push_back(ii(save[c1][pos1], 1));
                    pos1++;
                }
                else {
                    pos.push_back(ii(save[c2][pos2], -1));
                    pos2++;
                }
            }
            int cur = 0, last = 0;
            for (int i = 1 ; i < pos.size() ; i++) {
                cur += pos[i].S;
                if (pos[i].S == -1) last = i;
                if (last) res = max(res, cur-pre[last-1]);
                pre[i] = min(cur, pre[i-1]);
            }
        }
    cout << res;
    return 0;
}

Compilation message

roz.cpp: In function 'int main()':
roz.cpp:27:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             while(pos1 < save[c1].size() || pos2 < save[c2].size()) {
      |                   ~~~~~^~~~~~~~~~~~~~~~~
roz.cpp:27:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             while(pos1 < save[c1].size() || pos2 < save[c2].size()) {
      |                                             ~~~~~^~~~~~~~~~~~~~~~~
roz.cpp:28:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |                 if (pos1 == save[c1].size()) {
      |                     ~~~~~^~~~~~~~~~~~~~~~~~
roz.cpp:33:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |                 if (pos2 == save[c2].size()) {
      |                     ~~~~~^~~~~~~~~~~~~~~~~~
roz.cpp:48:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |             for (int i = 1 ; i < pos.size() ; i++) {
      |                              ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 2908 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 12 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 725 ms 11436 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 636 ms 11440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 738 ms 11584 KB Output is correct
2 Correct 579 ms 10904 KB Output is correct
3 Correct 605 ms 12928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 756 ms 11632 KB Output is correct
2 Correct 638 ms 25444 KB Output is correct
3 Correct 636 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 743 ms 11484 KB Output is correct
2 Correct 691 ms 26088 KB Output is correct
3 Correct 712 ms 13612 KB Output is correct