제출 #428532

#제출 시각아이디문제언어결과실행 시간메모리
428532tqbfjotldCheerleaders (info1cup20_cheerleaders)C++14
54 / 100
1584 ms10184 KiB
#include <bits/stdc++.h> using namespace std; int arr[(1<<18)+5]; int curarr[(1<<18)+5]; vector<int> f1(vector<int> v){ vector<int> nw; for (int x = 0; x<v.size(); x+=2){ nw.push_back(v[x]); } for (int x = 1; x<v.size(); x+=2){ nw.push_back(v[x]); } return nw; } int n,logn; vector<long long> allvals(int lpos, int sz ,vector<pair<int,int> > sorted){ if (sorted.size()==1){ return {0}; } // printf("called with sz %d, sortsz %d\n",sz,sorted.size()); long long inter1 = 0,inter2 = 0; vector<pair<int,int> >sortl,sortr; for (auto x : sorted){ if (x.second-lpos<sz/2) sortl.push_back(x); else sortr.push_back(x); } vector<long long> ans; long long c1 = 0; for (auto x : sortr){ while (c1<sortl.size() && sortl[c1]<x) c1++; inter2 += c1; } inter1 = ((long long)sortl.size()*(long long)(sortl.size()))-inter2; // printf("inter = %lld %lld\n",inter1,inter2); if (sortl.size()==1) return {inter1,inter2}; vector<long long> r1 = allvals(lpos,sz/2,sortl); vector<long long> r2 = allvals(lpos+sz/2,sz/2,sortr); for (int x = 0; x<sz/2; x++){ ans.push_back(r1[x]+r2[x]+inter1); } for (int x = 0; x<sz/2; x++){ ans.push_back(r1[x]+r2[x]+inter2); } return ans; } inline void scan(int &a){ a = 0; char ch = ' '; while (ch<'0' || ch>'9') ch = getchar(); while (ch>='0' && ch<='9'){ a = (a<<3)+(a<<1)+ch-'0'; ch = getchar(); } } int main(){ //freopen("test.txt","r",stdin); scan(n); logn = n; n = 1<<n; if (n==1){ printf("0\n"); return 0; } vector<int> t; for(int x = 0; x<n; x++){ scan(arr[x]); t.push_back(arr[x]); } vector<pair<int,int> > sorted; sorted.clear(); for (int x = 0; x<n; x++){ sorted.push_back({t[x],x}); } sort(sorted.begin(),sorted.end()); long long ans = 999999999999999999LL; for (int x = 0; x<logn; x++){ for (int x2 = 0; x2<n; x2++){ curarr[x2] = t[x2]; } auto res = allvals(0,n,sorted); for (auto x : res){ ans = min(ans,x); //printf("%lld \n",x); } t = f1(t); sorted.clear(); for (int x2 = 0; x2<n; x2++){ sorted.push_back({t[x2],x2}); } sort(sorted.begin(),sorted.end()); } printf("%lld\n",ans); }

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

cheerleaders.cpp: In function 'std::vector<int> f1(std::vector<int>)':
cheerleaders.cpp:9:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (int x = 0; x<v.size(); x+=2){
      |                     ~^~~~~~~~~
cheerleaders.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int x = 1; x<v.size(); x+=2){
      |                     ~^~~~~~~~~
cheerleaders.cpp: In function 'std::vector<long long int> allvals(int, int, std::vector<std::pair<int, int> >)':
cheerleaders.cpp:34:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         while (c1<sortl.size() && sortl[c1]<x) c1++;
      |                ~~^~~~~~~~~~~~~
#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...