# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1103942 | thangdz2k7 | Difference (POI11_roz) | C++17 | 115 ms | 3308 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// author : thembululquaUwU
// 3.9.2024
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
const int N = 1e6 + 1;
const int mod = 1e9 + 7;
const int nc = 26;
void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}
int n, cur[nc], Min[nc], ntm[nc];
string s;
void solve(){
cin >> n;
cin >> s; s = ' ' + s;
int ans = 0;
for (int u = 0; u < nc; ++ u){
for (int v = 0; v < nc; ++ v) {
cur[v] = 0;
Min[v] = 1e9;
ntm[v] = 0;
}
for (int i = 1; i <= n; ++ i){
int v = s[i] - 'a';
if (u == v) {
for (int k = 0; k < nc; ++ k) {
cur[k] ++;
if (k != u){
minl(ntm[k], cur[k]);
maxl(ans, cur[k] - Min[k]);
}
}
}
else {
cur[v] --;
minl(Min[v], ntm[v]);
ntm[v] = cur[v];
maxl(ans, cur[v] - Min[v]);
}
}
}
cout << ans;
}
int main(){
if (fopen("chenhlech.inp", "r")){
freopen("chenhlech.inp", "r", stdin);
freopen("chenhlech.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; // cin >> t;
while (t --) solve();
return 0;
}
Compilation message (stderr)
# | 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... |