Submission #128872

#TimeUsernameProblemLanguageResultExecution timeMemory
128872youngyojunRope (JOI17_rope)C++11
0 / 100
23 ms23928 KiB
#include <bits/stdc++.h> #define eb emplace_back using namespace std; const int MAXN = 1000055; int D[MAXN][2]; bitset<MAXN> chk; vector<int> G[MAXN]; int O[MAXN]; int A[MAXN], B[MAXN]; int N, M; int main() { ios::sync_with_stdio(false); cin >> N >> M; for(int i = 1; i <= N; i++) { cin >> A[i]; B[A[i]]++; } for(int i = 1; i <= M; i++) G[B[i]].eb(i); for(int i = M, c = 0; i; i--) for(int v : G[i]) O[++c] = v; for(int i = 1; i <= M; i++) G[i].clear(); for(int i = 1; i < N; i++) if(A[i] != A[i+1]) { G[A[i]].eb(i+1); G[A[i+1]].eb(-i); } for(int i = 1; i <= M; i++) { int ret = N, dg = 0; for(int v : G[i]) { D[A[abs(v)]][(0 < v ? v-1 : -v)&1]++; chk[A[abs(v)]] = true; dg++; } for(int oi = 1, c; oi <= N && oi <= dg+1; oi++) { c = O[oi]; if(c == i || chk[c]) continue; ret = -B[c]; break; } for(int v : G[i]) { int c = A[abs(v)], t = min(D[c][0], D[c][1]) - B[c]; if(t < ret) ret = t; } for(int v : G[i]) { D[A[abs(v)]][(0 < v ? v-1 : -v)&1] = 0; chk[A[abs(v)]] = false; } printf("%d\n", ret + N-B[i]); } 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...