Submission #336191

#TimeUsernameProblemLanguageResultExecution timeMemory
336191YJURope (JOI17_rope)C++14
45 / 100
2559 ms1260 KiB
#include<bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; const ll MOD=1e9+7; const ll MOD2=998244353; const ll N=1e6+5; const ll K=350; const ld pi=acos(-1); const ll INF=(1LL<<60); #define SQ(i) ((i)*(i)) #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define setp setprecision #define lwb lower_bound #define SZ(_a) (ll)_a.size() ll u[N],n,m,cnt[N],ans[N],dp[N],s[N]; ll ct(ll id,ll c){ ll ti=0; if(u[id]!=c)++ti; if(u[id-1]!=c)++ti; return ti; } ll upd(ll a){ ll res=INF,ma; if(u[1]!=a)++s[u[1]]; for(int i=3;i<=n;i+=2){ set<ll> ms; REP(j,2)ms.insert(u[i-j]); for(auto j:ms)s[j]+=max(0LL,ct(i,a)-ct(i,j)); } if((n&1)==0&&u[n]!=a)++s[u[n]]; ma=0; REP1(i,m)ma=max(ma,s[i]),s[i]=0; res=min(res,n-cnt[a]-ma); for(int i=2;i<=n;i+=2){ set<ll> ms; REP(j,2)ms.insert(u[i-j]); for(auto j:ms)s[j]+=max(0LL,ct(i,a)-ct(i,j)); } if((n&1)&&u[n]!=a)++s[u[n]]; ma=0; REP1(i,m)ma=max(ma,s[i]),s[i]=0; res=min(res,n-cnt[a]-ma); return res; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m; REP1(i,n)cin>>u[i],++cnt[u[i]]; REP1(i,m)ans[i]=upd(i); REP1(i,m)cout<<ans[i]<<"\n"; return 0; }
#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...