Submission #387628

#TimeUsernameProblemLanguageResultExecution timeMemory
387628casperwangCheerleaders (info1cup20_cheerleaders)C++14
0 / 100
2074 ms2764 KiB
#include <bits/stdc++.h> #define pb emplace_back #define All(x) x.begin(), x.end() using namespace std; #define debug(args...) kout("[ " + string(#args) + " ]", args) void kout() { cerr << endl; } template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); } template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; } const int MAXN = 17; int N; int ans; vector <int> a, c; vector <int> ord; inline int lb(int a) { return a &- a; } void init() { a.resize(1<<N); c.resize(1<<N); int now = 0; ord.pb(0); for (int i = 1; i < (1<<N); i++) { now ^= lb(i); ord.pb(now); } } int cnt() { int s = 0; for (int i = 0; i < (1<<N); i++) { for (int j = i+1; j < (1<<N); j++) { s += c[i] > c[j]; } } return s; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> N; init(); for (int i = 0; i < (1<<N); i++) cin >> a[i], c[a[i]] = i; ans = cnt(); for (int j = 0; j < N; j++) { for (int id : ord) { for (int i = 0; i < (1<<N); i++) c[i] ^= id; ans = min(ans, cnt()); } for (int i = 0; i < (1<<N); i++) { c[i] = (1<<(N-1)) * (c[i] & 1) + c[i] / 2; } } cout << ans << '\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...