Submission #1180275

#TimeUsernameProblemLanguageResultExecution timeMemory
1180275patgraRope (JOI17_rope)C++20
45 / 100
2594 ms584 KiB
#include <bits/stdc++.h> #define rep(a,b,c) for(auto a = (b); a != (c); a++) #define repD(a,b,c) for(auto a = (b); a != (c); a--) #define repIn(a, b) for(auto& a : (b)) #define repIn2(a, b, c) for(auto& [a, b] : (c)) constexpr bool dbg = 1; #define DEBUG if constexpr(dbg) #define DC DEBUG std::cerr #define eol std::endl #define ll long long #define pb push_back using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m; cin >> n >> m; vector<int> iniCol(n); rep(i, 0, n) cin >> iniCol[i]; vector<int> ans(m + 1, 1e9); rep(c1, 1, m + 1) rep(c2, 1, m + 1) { int cost; if(n % 2 == 0) { int cost1 = 0; int cost2 = 0; if(iniCol[0] != c1 && iniCol[0] != c2) cost1++; if(iniCol.back() != c1 && iniCol.back() != c2) cost1++; rep(i, 0, n / 2) { int mc1 = iniCol[2 * i], mc2 = iniCol[2 * i + 1]; if(mc1 == c1 || mc1 == c2) cost2 += mc2 != mc1; else if(mc2 == c1 || mc2 == c2) cost2++; else cost2 += 2; if(i * 2 + 2 >= n) break; mc1 = iniCol[2 * i + 2], mc2 = iniCol[2 * i + 1]; if(mc1 == c1 || mc1 == c2) cost1 += mc2 != mc1; else if(mc2 == c1 || mc2 == c2) cost1++; else cost1 += 2; } cost = min(cost1, cost2); } else { int cost1 = 0; int cost2 = 0; if(iniCol[0] != c1 && iniCol[0] != c2) cost1++; if(iniCol.back() != c1 && iniCol.back() != c2) cost2++; rep(i, 0, n / 2) { int mc1 = iniCol[2 * i], mc2 = iniCol[2 * i + 1]; if(mc1 == c1 || mc1 == c2) cost2 += mc2 != mc1; else if(mc2 == c1 || mc2 == c2) cost2++; else cost2 += 2; if(i * 2 + 2 >= n) break; mc1 = iniCol[2 * i + 2], mc2 = iniCol[2 * i + 1]; if(mc1 == c1 || mc1 == c2) cost1 += mc2 != mc1; else if(mc2 == c1 || mc2 == c2) cost1++; else cost1 += 2; } cost = min(cost1, cost2); } ans[c1] = min(ans[c1], cost); ans[c2] = min(ans[c2], cost); } rep(i, 0, m) cout << ans[i + 1] << '\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...