Submission #757003

#TimeUsernameProblemLanguageResultExecution timeMemory
757003Valters07Sequence (APIO23_sequence)C++17
0 / 100
996 ms74656 KiB
#include <bits/stdc++.h> #include "sequence.h" #define ll long long #define pb push_back #define fi first #define se second using namespace std; int sequence(int n, vector<int> a) { int peak = 0; while(peak+1<n&&a[peak]<=a[peak+1]) peak++; int res = 1, l = 0, r; for(int i = 1;i<n;i++) if(a[i]!=a[i-1]) l=i; else res=max(res,i-l+1); map<int,int> fir, lst, cnt; for(int i = 0;i<n;i++) { if(!fir.count(a[i])) fir[a[i]]=i; lst[a[i]]=i; cnt[a[i]]++; } for(auto x:cnt) { int mi = fir[x.fi]+(n-lst[x.fi]-1), cur = x.se, mx = n-mi-cur; if(abs(mi-mx)<=cur) res=max(res,cur); } return res; }

Compilation message (stderr)

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:13:25: warning: unused variable 'r' [-Wunused-variable]
   13 |     int res = 1, l = 0, r;
      |                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...