# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1012458 | Almonther | Difference (POI11_roz) | C++98 | 739 ms | 26464 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>
#define ll long long
#define co cout<<
#define suiii ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
// stuff
ll n;
string s;
ll mx=0;
vector<ll>v[100];
void solve(){
cin>>n>>s;
for(int i=0;i<n;i++) v[s[i]-'a'].push_back(i);
for(int i=0;i<27;i++){
if(v[i].size()==0) continue;
for(int j=0;j<27;j++){
ll l,r;
l=r=0;
vector<ll>arr;
while(l!=v[i].size()||r!=v[j].size()){
if(l==v[i].size()){
r++;
arr.push_back(-1);
}
else if(r==v[j].size()){
l++;
arr.push_back(1);
}
else if(v[i][l]<v[j][r]){
l++;
arr.push_back(1);
}
else{
r++;
arr.push_back(-1);
}
}
ll curr=0;
ll mn=1e18;
for(auto k:arr){
curr+=k;
if(k==-1) mn=min(mn,curr);
if(mn!=1e18) mx=max(mx,curr-mn);
}
}
}
co mx;
}
int main(){
suiii
int tt=1;
// cin>>tt;
while(tt--){
solve();
}
}
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... |