Submission #709446

#TimeUsernameProblemLanguageResultExecution timeMemory
709446myrcellaRope (JOI17_rope)C++17
55 / 100
55 ms21144 KiB
//by szh #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long,long long> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl #define pq priority_queue #define inf 0x3f #define rep(i,a,b) for (int i=a;i<(b);i++) #define MP make_pair #define SZ(x) (int(x.size())) #define ll long long #define mod 1000000007 #define ALL(x) x.begin(),x.end() void inc(int &a,int b) {a=(a+b)%mod;} void dec(int &a,int b) {a=(a-b+mod)%mod;} int lowbit(int x) {return x&(-x);} ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;} const int maxn = 5010; int n,m; int c[maxn*100]; int cntt[maxn][maxn],cnt[maxn]; int ans[maxn]; int tmp[maxn],tmpp[maxn]; void solve(int id) { rep(i,0,m) { tmp[i]=tmpp[i]=0; rep(j,0,m) cntt[i][j]=0; } if (id==1) tmpp[c[0]]++; for (int i=id;i<n;i+=2) { if (i+1<n) cntt[c[i]][c[i+1]]++,cntt[c[i+1]][c[i]]++,tmpp[c[i]]+=2; else tmpp[c[i]]++; if (i+1<n and c[i]!=c[i+1]) { tmp[c[i]]++; tmp[c[i+1]]++; tmpp[c[i+1]]+=2; } } rep(i,0,m) { ans[i] = min(ans[i],n-cnt[i]); rep(j,0,m) { if (i==j) continue; ans[i] = min(ans[i],(n-tmpp[i])-(cnt[j]-cntt[i][j])+tmp[i]); // cout<<i<<" "<<j<<" "<<(n-tmpp[i])<<" "<<(cnt[j]-cntt[i][j])<<" "<<tmp[i]<<endl; } } } int main() { // freopen("input.txt","r",stdin); std::ios::sync_with_stdio(false);cin.tie(0); cin>>n>>m; rep(i,0,m) ans[i] = n; rep(i,0,n) { cin>>c[i]; c[i]--; cnt[c[i]]++; } solve(0); solve(1); rep(i,0,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...