Submission #223375

# Submission time Handle Problem Language Result Execution time Memory
223375 2020-04-15T08:21:50 Z rainy Lampice (COCI19_lampice) C++17
0 / 110
26 ms 2048 KB
#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

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 time Memory Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 1408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 2048 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -