# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
223377 | rainy | Lampice (COCI19_lampice) | C++17 | 22 ms | 1792 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 MAXN 50005
#define pb push_back
using namespace std;
typedef vector<int> vi;
int N,A,B;
char c[MAXN];
map<char,vi> mp;
int nx[MAXN];
int main(){
scanf("%d",&N);
for(int i=0;i<N;i++){
scanf(" %c",&c[i]);
mp[c[i]].pb(i);
}
for(int i=0;i<N;i++){
auto it=upper_bound(mp[c[i]].begin(), mp[c[i]].end(),i);
if(it==mp[c[i]].end())nx[i]=-1;
else nx[i]=*it;
}
for(int i=0;i<N-1;i++){
scanf("%d%d",&A,&B);
assert(abs(A-B)==1);
}
int si=0;
int ans=0;
for(int j=1;j<N;j++){
if(nx[j]!=nx[j-1]-1){
if(nx[j-1]-(j-1)==1){
ans=max(ans, 2*(j-si));
}
else if(nx[j-1]-(j-1)==2){
ans=max(ans, 2*(j-si)+1);
}
si=j;
}
}
printf("%d\n",ans);
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... |