Submission #1028951

#TimeUsernameProblemLanguageResultExecution timeMemory
1028951vjudge1Cheerleaders (info1cup20_cheerleaders)C++17
54 / 100
277 ms12620 KiB
#include <bits/stdc++.h> using namespace std; #define int long long void f(){ #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); //f(); int n; cin >> n; vector<int> a((1<<n)), pos((1<<n)); for(auto &i: a) cin >> i; for(int i=0; i<(1<<n); i++){ pos[a[i]]=i; } auto get_xor=[&](int y){ vector<int> op; for(int i=0; i<n; i++){ op.push_back(0); if((1<<i)&&y){ op.push_back(1); } } return op; }; //0 is odd even thing //1 is swapping first half and last half auto d=[&](vector<int> &g, int type){ if(type==0){ for(int i=0; i<g.size(); i++){ if(g[i]%2){ g[i]=g[i]/2+(1<<(n-1)); } else g[i]/=2; } } else{ for(int i=0; i<n; i++){ g[i]^=(1<<n-1); } } }; int ans=1e18; vector<int> op; for(int i=0; i<n; i++){ vector cnt(n, vector((1<<n), 0)); vector<array<int, 2>> p(n); for(int l=0; l<(1<<n); l++){ int val=0; for(int j=n-1; j>=0; j--){ if(pos[l]&(1<<j)){ p[j][1]+=cnt[j][val]; val+=(1<<j); } else{ p[j][0]+=cnt[j][val+(1<<j)]; } cnt[j][val]++; } } int sum=0, xo=0; for(int i=0; i<n; i++){ if(p[i][1]<p[i][0]) xo+=(1<<i); sum+=min(p[i][0], p[i][1]); } vector<int> val=get_xor(xo); if(sum<ans){ ans=sum; op.clear(); for(int l=0; l<i; l++) op.push_back(0); for(auto l: val) op.push_back(l); } d(pos, 0); } if(n==0) ans=0; cout<<ans<<"\n"; for(auto i: op) cout<<(i==0?2:1); }

Compilation message (stderr)

cheerleaders.cpp: In lambda function:
cheerleaders.cpp:30:9: warning: '<<' in boolean context, did you mean '<'? [-Wint-in-bool-context]
   30 |    if((1<<i)&&y){
      |       ~~^~~~
cheerleaders.cpp: In lambda function:
cheerleaders.cpp:42:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |    for(int i=0; i<g.size(); i++){
      |                 ~^~~~~~~~~
cheerleaders.cpp:51:16: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   51 |     g[i]^=(1<<n-1);
      |               ~^~
cheerleaders.cpp: In function 'void f()':
cheerleaders.cpp:8:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  freopen("in.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
cheerleaders.cpp:9:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  freopen("out.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...