Submission #223375

#TimeUsernameProblemLanguageResultExecution timeMemory
223375rainyLampice (COCI19_lampice)C++17
0 / 110
26 ms2048 KiB
#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=1; 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)

lampice.cpp: In function 'int main()':
lampice.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
     ~~~~~^~~~~~~~~
lampice.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c",&c[i]);
         ~~~~~^~~~~~~~~~~~~
lampice.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&A,&B);
         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...