답안 #1002138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1002138 2024-06-19T10:23:24 Z votranngocvy Difference (POI11_roz) C++14
20 / 100
448 ms 14180 KB
#include <bits/stdc++.h>
using namespace std;

#define NAME "differ"
const int N = 1e6 + 5;
vector<int>pos[30];
int n,ans;
char s[N];

void calc(int a,int b) {
    vector<int>vec;
    int i = 0,j = 0;
    while (i < (int)pos[a].size() && j < (int)pos[b].size()) {
        if (pos[a][i] < pos[b][j]) {
            vec.push_back(1);
            i++;
        }
        else {
            vec.push_back(-1);
            j++;
        }
    }
    while (i < (int)pos[a].size()) {
        vec.push_back(1);
        i++;
    }
    while (j < (int)pos[b].size()) {
        vec.push_back(-1);
        j++;
    }
    int sum = 0;
    for (auto x: vec) {
        sum = max(sum + x,x);
        ans = max(ans,sum);
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> s[i];
        pos[s[i] - 'a'].push_back(i);
    }
    for (int i = 0; i < 26; i++)
        for (int j = 0; j < 26; j++) 
            if (i != j && pos[i].size() && pos[j].size()) calc(i,j);
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 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 Incorrect 0 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 1116 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 423 ms 7640 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 439 ms 7824 KB Output is correct
2 Correct 347 ms 6088 KB Output is correct
3 Correct 156 ms 7228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 422 ms 8100 KB Output is correct
2 Correct 59 ms 13084 KB Output is correct
3 Incorrect 107 ms 8316 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 448 ms 7736 KB Output is correct
2 Correct 36 ms 14180 KB Output is correct
3 Correct 193 ms 8008 KB Output is correct