제출 #369354

#제출 시각아이디문제언어결과실행 시간메모리
369354dooweyCheerleaders (info1cup20_cheerleaders)C++14
0 / 100
2084 ms1900 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); void brute(){ int n; cin >> n; int m = (1 << n); vector<int> h(m); vector<int> go(m); for(int i = 0 ; i < m ; i ++ ){ cin >> h[i]; } int best = (int)1e9; vector<int> outp; int cur; vector<int> pp; for(int shift = 0; shift <= n; shift ++) { for(int mask = 0 ; mask < (1 << (shift + 1)); mask ++ ){ cur = 0; pp.clear(); for(int i = 0 ;i < m ; i ++ ){ go[i] = i; } for(int p = 0 ; p <= shift; p ++ ){ if(p){ pp.push_back(2); for(int j =0 ; j < m ; j ++ ){ go[j] = (go[j] >> 1)|((go[j]&1)<<(n-1)); } } if(mask & (1 << p)){ pp.push_back(1); for(int j = 0 ;j < m ; j ++ ){ go[j] ^= (1 << (n - 1)); } } } vector<int> seq(m); for(int i = 0 ; i < m ; i ++ ){ seq[go[i]] = h[i]; } for(int i = 0 ; i < m ; i ++ ){ for(int j = i + 1 ; j < m ; j ++ ){ if(seq[i] > seq[j]){ cur ++ ; } } } if(cur < best){ best = cur; outp = pp; } } } cout << best << "\n"; for(auto x : outp){ cout << x; } cout << "\n"; } int main(){ fastIO; brute(); return 0; int n; cin >> n; int m = (1 << n); vector<int> H(m); for(int i = 0 ; i < m ; i ++ ){ cin >> H[i]; } ll best = (ll)1e18; vector<int> soln; ll cur; ll inv; ll w0, w1; int pp; int z; for(int shf = 0; shf < n; shf ++ ){ vector<int> ord; vector<bool> swi; for(int j = shf; j < n - 1; j ++) { ord.push_back(j); swi.push_back(0); } ord.push_back(n-1); swi.push_back(1); for(int j = 0 ; j < shf; j ++ ){ ord.push_back(j); swi.push_back(1); } vector<vector<pii>> pv; vector<vector<pii>> nw; pv.push_back({}); cur = 0; for(int i = 0 ;i < m ; i ++ ){ pv.back().push_back(mp(H[i],i)); } sort(pv.back().begin(), pv.back().end()); for(int i = n - 1; i >= 0; i -- ){ nw.clear(); w0 = w1 = 0; for(auto x : pv){ vector<pii> f[2]; for(auto y : x){ if((y.se & (1 << ord[i]))){ f[1].push_back(y); } else{ f[0].push_back(y); } } pp = 0; inv = 0; z = f[0].size(); for(auto x : f[0]){ while(pp < f[1].size() && f[1][pp].fi < x.fi){ pp ++ ; } inv += pp; } w0 += inv; w1 += (z * 1ll * z) - inv; nw.push_back(f[0]); nw.push_back(f[1]); } pv = nw; if(swi[i] == 0 || (w0 < w1)){ cur += w0; swi[i]=false; } else{ cur += w1; } } if(cur < best){ best = cur; } } cout << best << "\n12"; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

cheerleaders.cpp: In function 'int main()':
cheerleaders.cpp:127:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |                     while(pp < f[1].size() && f[1][pp].fi < x.fi){
      |                           ~~~^~~~~~~~~~~~~
#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...