이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int M = 26;
int n;
string s;
int best[M][M];
int invalid[M][M];
int update_local[M];
int update_global[M];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>s;
memset(update_local, 0, sizeof(update_local));
memset(update_global, 0, sizeof(update_global));
for (int i = 0; i < M; i++)
for (int j = 0; j < M; j++)
best[i][j] = invalid[i][j] = -1e9;
int ans = 0;
for (int i = 0; i < n; i++) {
// [i][s[i]-'a']--
update_global[s[i]-'a']--;
// [s[i]-'a'][i]++
update_local[s[i]-'a']++;
for (int c = 0; c < M; c++) if (c != s[i]-'a') {
// make things valid
best[c][s[i]-'a'] = max(best[c][s[i]-'a'], invalid[c][s[i]-'a']);
ans = max(ans, best[s[i]-'a'][c] + update_local[s[i]-'a'] + update_global[c]);
// now new updates are invalid until activated
invalid[s[i]-'a'][c] = max(invalid[s[i]-'a'][c], 1 - update_local[s[i]-'a'] - update_global[c]);
}
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |