# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40946 | wzy | Difference (POI11_roz) | C++14 | 833 ms | 16684 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.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pii pair<int,int>
#define ieps (int) 1e6
#define eps (int) 1e9
#define mp make_pair
#define pb push_back
vector<int> hist[27];
int n;
string s;
int ansj = 0;
void solve(int pos , int neg){
int cnta = 0 , cntb = 0 , curr = 0 , leftp = 0 , foineg = false;
for(int i = 0 ; i < hist[pos].size() + hist[neg].size() ; i++){
if(cnta == hist[pos].size()){
if(!foineg){
ansj = max(ansj , curr - 1);
}
return;
}
else if(cntb == hist[neg].size()){
if(!foineg){
break;
}
while(cnta++ <hist[pos].size()){
curr++;
}
if(foineg)ansj = max(ansj , curr);
break;
}
else{
if(hist[pos][cnta] < hist[neg][cntb]){
curr++;
cnta++;
if(foineg) ansj = max(ansj , curr);
}
else{
cntb++;
if(curr - 1 >=0){
curr--;
foineg = true;
if(foineg) ansj = max(ansj , curr);
}
else{
foineg = false;
curr = 0;
}
}
}
}
return;
}
int32_t main(){
scanf("%d" , &n);
s.resize(n);
scanf("%s" , &s[0]);
for(int i = 0 ; i < n;i++){
hist[s[i] - 'a'].pb(i);
}
for(char i = 'a' ; i <= 'z' ; i++){
for(char j = 'a' ; j <= 'z'; j++){
if(i == j) continue;
solve(i-'a' , j-'a');
}
}
for(int i = 0 ; i < n;i++){
hist[s[i] - 'a'].clear();
}
reverse(s.begin() , s.end());
for(int i = 0 ; i < n;i++){
hist[s[i] - 'a'].pb(i);
}
for(char i = 'a' ; i <= 'z' ; i++){
for(char j = 'a' ; j <= 'z'; j++){
if(i == j) continue;
solve(i-'a' , j-'a');
}
}
printf("%d\n" , ansj);
}
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... |