제출 #428500

#제출 시각아이디문제언어결과실행 시간메모리
428500tqbfjotldCheerleaders (info1cup20_cheerleaders)C++14
25 / 100
2009 ms11624 KiB
#include <bits/stdc++.h> using namespace std; int arr[(1<<17)+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, vector<int> things,vector<pair<int,int> > sorted){ if (things.size()==1){ return {0}; } long long inter1 = 0,inter2 = 0; vector<pair<int,int> >sortl,sortr; for (auto x : sorted){ if (x.second-lpos<things.size()/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<int> l,r; for (int x = 0; x<things.size(); x++){ if (x<things.size()/2) l.push_back(things[x]); else r.push_back(things[x]); } vector<long long> r1 = allvals(lpos,l,sortl); vector<long long> r2 = allvals(lpos+things.size()/2,r,sortr); for (int x = 0; x<l.size(); x++){ ans.push_back(r1[x]+r2[x]+inter1); } for (int x = 0; x<l.size(); x++){ ans.push_back(r1[x]+r2[x]+inter2); } return ans; } int main(){ scanf("%d",&n); logn = n; n = 1<<n; vector<int> t; for(int x = 0; x<n; x++){ scanf("%d",&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++){ auto res = allvals(0,t,sorted); for (auto x : res){ ans = min(ans,x); //printf("%lld \n",x); } t = f1(t); sorted.clear(); for (int x = 0; x<n; x++){ sorted.push_back({t[x],x}); } sort(sorted.begin(),sorted.end()); } printf("%lld\n",ans); }

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

cheerleaders.cpp: In function 'std::vector<int> f1(std::vector<int>)':
cheerleaders.cpp:8:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int x = 0; x<v.size(); x+=2){
      |                     ~^~~~~~~~~
cheerleaders.cpp:11:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int x = 1; x<v.size(); x+=2){
      |                     ~^~~~~~~~~
cheerleaders.cpp: In function 'std::vector<long long int> allvals(int, std::vector<int>, std::vector<std::pair<int, int> >)':
cheerleaders.cpp:26:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if (x.second-lpos<things.size()/2) sortl.push_back(x);
      |             ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
cheerleaders.cpp:32: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]
   32 |         while (c1<sortl.size() && sortl[c1]<x) c1++;
      |                ~~^~~~~~~~~~~~~
cheerleaders.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int x = 0; x<things.size(); x++){
      |                     ~^~~~~~~~~~~~~~
cheerleaders.cpp:40:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         if (x<things.size()/2) l.push_back(things[x]);
      |             ~^~~~~~~~~~~~~~~~
cheerleaders.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int x = 0; x<l.size(); x++){
      |                     ~^~~~~~~~~
cheerleaders.cpp:48:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int x = 0; x<l.size(); x++){
      |                     ~^~~~~~~~~
cheerleaders.cpp: In function 'int main()':
cheerleaders.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
cheerleaders.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         scanf("%d",&arr[x]);
      |         ~~~~~^~~~~~~~~~~~~~
#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...