Submission #1001020

#TimeUsernameProblemLanguageResultExecution timeMemory
1001020OtalpRope (JOI17_rope)C++17
55 / 100
2463 ms262148 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define ff first #define ss second #define pb push_back map<pii, int> dp[2]; int cnt[1001000]; int a[1001000]; vector<int> d[1000100]; void solve(){ int n, m; cin>>n>>m; for(int i=1; i<=n; i++){ cin>>a[i]; cnt[a[i]] ++; } vector<pii> g; for(int i=1; i<=m; i++){ g.pb({cnt[i], i}); } sort(g.begin(), g.end()); int h[2]={0, 0}; for(int i=1; i+1<=n; i+=2){ int l=a[i], r=a[i + 1]; dp[1][{l, r}] ++; dp[1][{r, l}] ++; h[1] ++; d[l].pb(r); d[r].pb(l); } for(int i=2; i+1<=n; i+=2){ int l=a[i], r=a[i + 1]; dp[0][{l, r}] ++; dp[0][{r, l}] ++; h[0] ++; d[l].pb(r); d[r].pb(l); } for(int i=1; i<=m; i++){ int ans = n - cnt[i]; int ls = g.size() - 1; map<int, int> us; us[i] = 1; for(int j: d[i]){ if(j == i) continue; for(int k=0; k<2; k++){ ans = min(ans, n-cnt[i]-cnt[j]+dp[k][{i, j}]); } us[j] = 1; } while(us[g[ls].ss]) ls--; if(ls >= 0) ans = min(ans, n - cnt[i] - g[ls].ff); cout<<ans<<'\n'; } } signed main(){ solve(); }
#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...