# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1002197 |
2024-06-19T10:54:26 Z |
son2008 |
Difference (POI11_roz) |
C++17 |
|
701 ms |
37784 KB |
#include<bits/stdc++.h>
using namespace std;
#define task "differ"
#define ii pair<int,int>
#define fi first
#define se second
// #define int long long
#define ld double
#define mp make_pair
#define lg2 20
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define fii fi.fi
#define fis fi.se
#define sfi se.fi
#define see se.se
int dx[]={0LL,0LL,1,-1,1,1,-1,-1};
int dy[]={1,-1,0LL,0LL,1,-1,1,-1};
const int maxn=1e6+5;
const int mod=1e9+7;
int n,s1[maxn][26],pre[maxn],tr[maxn],minn[maxn];
int b[maxn];
string s;
vector<int>a[maxn];
void sub1(){
for(int i=1;i<=n;i++){
for(int j=0;j<26;j++)
s1[i][j]=s1[i-1][j];
s1[i][s[i]-'a']++;
}
int ans=0;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
int maxx=0,minn=1e9;
for(int k=0;k<26;k++){
if(s1[j][k]-s1[i-1][k]==0)break;
maxx=max(maxx,s1[j][k]-s1[i-1][k]);
minn=min(minn,s1[j][k]-s1[i-1][k]);
}
ans=max(ans,maxx-minn);
}
}
cout<<ans;
}
void sub23(){
for(int i=1;i<=n;i++){
a[s[i]-'a'].push_back(i);
}
int ans=0;
for(int i=0;i<26;i++){
for(int j=0;j<26;j++){
int n=a[i].size(),n1=a[j].size();
if(n>0&&n1>0&&i!=j){
int l=0,r=0,m=0;
while(l<n&&r<n1){
if(a[i][l]<a[j][r]){
m++;
b[m]=1;
l++;
}
else{
m++;
b[m]=-1;
r++;
}
}
while(l<n){
m++;
b[m]=1;
l++;
}
while(r<n1){
m++;
b[m]=-1;
r++;
}
/* for(int k=1;k<=m;k++)
cout<<b[k]<<" ";
cout<<'\n';*/
tr[0]=-1;
for(int k=1;k<=m;k++){
if(b[k]==-1)
tr[k]=k-1;
else
tr[k]=tr[k-1];
}
int sum=0;
for(int k=1;k<=m;k++){
sum+=b[k];
if(b[k]==-1)
ans=max(ans,sum-minn[k-1]);
else{
if(tr[k]!=-1)
ans=max(ans,sum-minn[tr[k]]);
}
minn[k]=min(minn[k-1],sum);
}
}
}
}
cout<<ans;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);}
cin>>n>>s;
s=' '+s;
sub23();
}
Compilation message
roz.cpp: In function 'int main()':
roz.cpp:108:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
108 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
roz.cpp:109:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
109 | freopen(task".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23896 KB |
Output is correct |
3 |
Correct |
10 ms |
23776 KB |
Output is correct |
4 |
Correct |
9 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23884 KB |
Output is correct |
2 |
Correct |
9 ms |
23836 KB |
Output is correct |
3 |
Correct |
9 ms |
23940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23896 KB |
Output is correct |
3 |
Correct |
13 ms |
23944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
9 ms |
23896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
24744 KB |
Output is correct |
2 |
Correct |
12 ms |
23896 KB |
Output is correct |
3 |
Correct |
12 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
681 ms |
32804 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
695 ms |
32728 KB |
Output is correct |
2 |
Correct |
503 ms |
31712 KB |
Output is correct |
3 |
Correct |
68 ms |
31404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
701 ms |
32740 KB |
Output is correct |
2 |
Runtime error |
72 ms |
37784 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
661 ms |
32876 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |