Submission #336187

#TimeUsernameProblemLanguageResultExecution timeMemory
336187YJURope (JOI17_rope)C++14
45 / 100
2586 ms2028 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]; ll ct(ll id,ll c){ ll ti=0; if(u[id]!=c)++ti; if(u[id-1]!=c)++ti; return ti; } ll ck(ll a,ll b){ ll ta=0,tb=0,tmp=INF; if(a==b)return n-cnt[a]; REP1(i,n){ if(u[i]==a)++ta; if(u[i]==b)++tb; dp[i]=INF; if(i>=2){ dp[i]=min(dp[i],dp[i-2]+min(ct(i,a),ct(i,b))); }else{ dp[i]=1-(u[i]==a||u[i]==b?1:0); } tmp=min(tmp,dp[i]+(n-i)-max(cnt[a]-ta,cnt[b]-tb)); } return tmp; } 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]=INF; REP1(i,m)REP1(j,i){ ll tmp=ck(i,j); ans[i]=min(ans[i],tmp); ans[j]=min(ans[j],tmp); } 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...