제출 #128072

#제출 시각아이디문제언어결과실행 시간메모리
128072EntityITRope (JOI17_rope)C++14
80 / 100
2542 ms168804 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back using ii = pair<int, int>; int n, m; vector<int> c, cnt; vector< vector<int> > vec[2]; multiset<int> rem; void upd (int col, int val) { rem.erase(rem.find(cnt[col]) ); cnt[col] += val; rem.insert(cnt[col]); } int solve (int col, bool _) { int cnt_rem = n - cnt[col]; for (int _col : vec[_][col]) upd (_col, -1), --cnt_rem; rem.erase(rem.find(cnt[col]) ); if (rem.size() ) cnt_rem -= *rem.rbegin(); rem.insert(cnt[col]); for (int _col : vec[_][col]) upd (_col, 1); return cnt_rem + (int)vec[_][col].size(); } int main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; cnt.assign(m, 0); c.assign(n, 0); for (int i = 0; i < n; ++i) cin >> c[i], --c[i], ++cnt[ c[i] ]; for (int _ = 0; _ < 2; ++_) { vec[_].assign(m, vector<int>() ); vector<int> sz_vec(m, 0); for (int i = _; i + 1 < n; i += 2) { if (c[i] != c[i + 1]) { ++sz_vec[ c[i] ]; ++sz_vec[ c[i + 1] ]; } } for (int i = 0; i < m; ++i) vec[_][i].assign(sz_vec[i], 0); sz_vec.assign(m, 0); for (int i = _; i + 1 < n; i += 2) { if (c[i] != c[i + 1]) { vec[_][ c[i] ][ sz_vec[ c[i] ]++ ] = c[i + 1]; vec[_][ c[i + 1] ][ sz_vec[ c[i + 1] ]++ ] = c[i]; } } } for (int col = 0; col < m; ++col) rem.insert(cnt[col]); for (int col = 0; col < m; ++col) cout << min(solve(col, 0), solve(col, 1) ) << '\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...