제출 #534492

#제출 시각아이디문제언어결과실행 시간메모리
534492rk42745417Rope (JOI17_rope)C++17
0 / 100
1 ms316 KiB
/* -------------- | / | | / | | / | * |/ | | ------ * | | | | / \ | | |\ | | | |\ | \ | | | \ | | | | \ | \ | | | \ | | \ / \ | V | | \ \__/| ----- \ | */ #include <bits/stdc++.h> using namespace std; #define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n" #define print(x) emilia_mata_tenshi(#x, begin(x), end(x)) template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) { cerr << "\e[1;33m" << s << " = ["; while(l != r) { cerr << *l; cerr << (++l == r ? ']' : ','); } cerr << "\e[0m\n"; } #define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL); using ll = int64_t; using ull = uint64_t; using ld = long double; using uint = uint32_t; const double EPS = 1e-8; const int INF = 0x3F3F3F3F; const ll LINF = 4611686018427387903; const int MOD = 1e9+7; static int Lamy_is_cute = []() { EmiliaMyWife return 48763; }(); /*--------------------------------------------------------------------------------------*/ signed main() { int n, m; cin >> n >> m; vector<int> arr(n); for(int &a : arr) cin >> a; vector<int> ans(m + 1, INF); for(int st : {1, 2}) { vector<int> cost(m + 1); vector<map<int, int>> adj(m + 1); for(int i = st; i < n; i += 2) { int a = arr[i - 1], b = arr[i]; if(a == b) cost[a] += 2; else { adj[a][b]++; adj[b][a]++; cost[a]++; cost[b]++; } } if(st == 2) cost[arr[0]]++; if((st == 2) ^ (n % 2)) cost[arr.back()]++; int mx = 0, smx = 0; for(int i = 1; i <= m; i++) { if(cost[i] > mx) swap(mx, smx), mx = cost[i]; else smx = max(smx, cost[i]); } for(int i = 1; i <= m; i++) { int res = 0; if(cost[i] == mx) res = smx; else res = mx; for(const auto &[a, c] : adj[i]) res = max(res, cost[a] - c); ans[i] = min(ans[i], n - (res + cost[i])); } } for(int i = 1; i <= m; i++) cout << ans[i] << '\n'; }
#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...