Submission #387668

#TimeUsernameProblemLanguageResultExecution timeMemory
3876688e7Cheerleaders (info1cup20_cheerleaders)C++14
8 / 100
1377 ms1860 KiB
//Challenge: Accepted #include <iostream> #include <algorithm> #include <vector> #include <utility> #define ll long long #define maxn 150005 #define pii pair<int, int> #define ff first #define ss second #define io ios_base::sync_with_stdio(0);cin.tie(0); using namespace std; //#include <bits/extc++.h> //using namespace __gnu_pbds; //template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //find by order, order of key int a[maxn]; int bit[maxn], shift[maxn][17]; void modify(int ind, int val) { for (;ind < maxn;ind += ind & (-ind)) bit[ind] += val; } int query(int ind) { int ret = 0; for (;ind > 0;ind -= ind & (-ind)) ret += bit[ind]; return ret; } ll solve(int pos, int type, int n) { ll ret = 0; type = n - 1 - type; int dif = (type - pos + n) % n; for (int i = 0;i < (1<<(n - 1 - type));i++) { for (int j = 0;j < (1<<type);j++) { int ind = shift[dif][(i<<(type+1)) + j]; //cout << ind << endl; modify(a[ind], 1); } for (int j = 0;j < (1<<type);j++) { //cout << int ind = shift[dif][(i<<(type+1)) + (1<<type) + j]; //cout << " " << " " << ind << endl; ret += query(a[ind]); } for (int j = 0;j < (1<<type);j++) { int ind = shift[dif][(i<<(type+1)) + j]; modify(a[ind], -1); } } return ret; } int main() { io int n; cin >> n; for (int i = 0;i < (1<<n);i++) { cin >> a[i], a[i]++; shift[0][i] = i; int tmp = i; //cout << tmp << " "; for (int j = 1;j < n;j++) { //cout << (tmp & (1<<(n - 1))) << endl; int b = (tmp & (1<<(n - 1))) ? 1 : 0; tmp -= (tmp & (1<<(n - 1))); tmp = (tmp<<1) + b; shift[j][i] = tmp; //cout << shift[j][i] << " "; } //cout << endl; } ll best = 0; int bind = 0, bp = 0; for (int p = 0;p < n;p++) { //position of the highest bit is p ll val = 0; int num = 0; for (int t = 0;t < n;t++) { ll z = solve((p - t + n) % n, t, n); //cout << t << " " << (1LL<<t) * (1LL<<(n - 1 - t)) * (1LL<<(n - 1 - t)) << endl; ll o = (1LL<<t) * (1LL<<(n - 1 - t)) * (1LL<<(n - 1 - t)) - z; //cout << p << " " << t << " " << z << " " << o << "\n"; val += max(z, o); num<<=1; if (o > z) { num += 1; } } if (val > best) { best = val; bind = num, bp = p; } } //cout << best << endl; int tot = 1<<n; cout << (ll)tot * (tot - 1) / 2 - best << "\n"; //cout << bind << " " << bp << endl; } /* 2 0 3 1 2 3 2 3 7 6 1 4 5 0 4 1 4 8 5 3 6 12 13 10 11 2 9 14 0 15 7 */

Compilation message (stderr)

cheerleaders.cpp: In function 'int main()':
cheerleaders.cpp:73:6: warning: variable 'bind' set but not used [-Wunused-but-set-variable]
   73 |  int bind = 0, bp = 0;
      |      ^~~~
cheerleaders.cpp:73:16: warning: variable 'bp' set but not used [-Wunused-but-set-variable]
   73 |  int bind = 0, bp = 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...