제출 #369363

#제출 시각아이디문제언어결과실행 시간메모리
369363dooweyCheerleaders (info1cup20_cheerleaders)C++14
100 / 100
1854 ms19068 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); int main(){ fastIO; int n; cin >> n; if(n == 0){ cout << 0 << "\n"; return 0; } 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; vector<int> cha; for(int shf = 0; shf < n; shf ++ ){ vector<int> ord; vector<bool> swi(n); for(int j = shf; j < n - 1; j ++) { ord.push_back(j); } ord.push_back(n-1); for(int j = 0 ; j < shf; j ++ ){ ord.push_back(j); } 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()); cha.clear(); 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(w0 < w1){ cur += w0; } else{ cur += w1; swi[ord[i]]=true; } } if(cur < best){ best = cur; soln.clear(); for(int j = 0 ; j < n; j ++ ){ if(swi[(j + n - 1) % n]) soln.push_back(1); soln.push_back(2); } for(int j = 0; j < shf; j ++ ){ soln.push_back(2); } } } cout << best << "\n"; for(auto x : soln) cout << x; return 0; }

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

cheerleaders.cpp: In function 'int main()':
cheerleaders.cpp:70: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]
   70 |                     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...