Submission #533463

#TimeUsernameProblemLanguageResultExecution timeMemory
533463hhhhauraCheerleaders (info1cup20_cheerleaders)C++14
25 / 100
213 ms2380 KiB
#define wiwihorz #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse") #pragma loop-opt(on) #define rep(i, a, b) for(int i = a; i <= b; i ++) #define rrep(i, a, b) for(int i = b; i >= a; i--) #define ceil(a, b) ((a + b - 1) / (b)) #define all(x) x.begin(), x.end() #define lld long double #define pii pair<int, int> #define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()) using namespace std; #define INF 1000000000 #define MOD 1000000007 #define eps (1e-9) #ifdef wiwihorz #define print(a...) cerr<<"Line "<<__LINE__<<":",kout("[" + string(#a) + "] = ", a) void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L)==R], ++L;} void kout() { cerr << endl; } template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);} #else #define print(...) 0 #define vprint(...) 0 #endif #define x first #define y second namespace solver { int n, tot, mask; vector<int> a, b, cnt; void init_(int _n) { n = _n; tot = 1 << n; mask = tot - 1; a.assign(tot, 0); b.assign(tot, 0); cnt.assign(tot, 0); } string get_ans(pii opt) { string s = "2"; rep(i, 1, opt.x) s += "2"; rep(i, 0, n - 1) { if((opt.y >> i) & 1) s += "1"; if(i != n - 1) s += "2"; } return s; } void solve() { pii opt = {0, 0}; int ans = INF; vector<int> tp(tot, 0); rep(i, 0, tot - 1) tp[a[i]] = i; a = tp; rep(i, 0, n - 1) { pii p = {i, 0}; int best = 0; rep(j, 0, tot - 1) b[j] = mask & ((a[j] >> (n - i)) | (a[j] << i)); // rep(j, 0, tot - 1) print(i, j, bitset<2>(a[j]), bitset<2>(b[j])); rep(j, 1, n) { int L = 0, R = 0, bot = 1 << (n - j); int val = ((1 << j) - 1) << (n - j); // print(i, j, bitset<2>(bot), bitset<2>(val)); cnt.assign(tot, 0); rep(k, 0, tot - 1) { int cur = b[k] & val; int to = cur ^ bot; if(cur > to) R += cnt[to]; else L += cnt[to]; cnt[cur] ++; // print(L, R); } // print(L, R); if(L > R) p.y |= bot; best += min(L, R); } // print(best); if(best < ans) opt = p, ans = best; } cout << ans << "\n"; cout << get_ans(opt) << "\n"; } }; using namespace solver; signed main() { ios::sync_with_stdio(false), cin.tie(0); int n; cin >> n; init_(n); rep(i, 0, tot - 1) cin >> a[i]; if(n == 1) cout << "0\n"; else solve(); return 0; }

Compilation message (stderr)

cheerleaders.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    5 | #pragma loop-opt(on)
      | 
cheerleaders.cpp:20:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L)==R], ++L;}
      |             ^~~~
cheerleaders.cpp:20:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L)==R], ++L;}
      |                     ^~~~
#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...