제출 #200000

#제출 시각아이디문제언어결과실행 시간메모리
200000Mercenary저울 (IOI15_scales)C++14
100 / 100
75 ms640 KiB
#include<bits/stdc++.h> using namespace std; #include"scales.h" #define mp make_pair #define pb push_back const int maxn = 2e6; vector<vector<int>> perm; vector<int> lim ={243,81,27,9,3,1}; vector<int> p; int a[maxn] , b[maxn][3]; int root , nTime = 0; vector<pair<int,vector<int>>> query; vector<vector<int>> GetLig(vector<int> & p , vector<int> &a){ vector<vector<int>> res(3); vector<int> tmp(3);iota(tmp.begin(),tmp.end(),0); for(auto & c : p){ sort(tmp.begin(),tmp.end(),[&](const int x , const int y){ return perm[c][a[x]] < perm[c][a[y]]; }); res[tmp[0]].pb(c); } return res; } vector<vector<int>> GetHea(vector<int> & p , vector<int> &a){ vector<vector<int>> res(3); vector<int> tmp(3);iota(tmp.begin(),tmp.end(),0); for(auto & c : p){ sort(tmp.begin(),tmp.end(),[&](const int x , const int y){ return perm[c][a[x]] < perm[c][a[y]]; }); res[tmp[2]].pb(c); } return res; } vector<vector<int>> GetMed(vector<int> & p , vector<int> &a){ vector<vector<int>> res(3); vector<int> tmp(3);iota(tmp.begin(),tmp.end(),0); for(auto & c : p){ sort(tmp.begin(),tmp.end(),[&](const int x , const int y){ return perm[c][a[x]] < perm[c][a[y]]; }); res[tmp[1]].pb(c); } return res; } vector<vector<int>> GetNexLig(vector<int> & p , vector<int> &a){ vector<vector<int>> res(3); vector<int> tmp(3);iota(tmp.begin(),tmp.end(),0); for(auto & c : p){ sort(tmp.begin(),tmp.end(),[&](const int x , const int y){ return perm[c][a[x]] < perm[c][a[y]]; }); if(perm[c][a[tmp[2]]] <= perm[c][a[3]]){ res[tmp[0]].pb(c); }else if(perm[c][a[tmp[0]]] > perm[c][a[3]]){ res[tmp[0]].pb(c); }else if(perm[c][a[tmp[1]]] > perm[c][a[3]]){ res[tmp[1]].pb(c); }else res[tmp[2]].pb(c); } return res; } vector<vector<int>> Get(vector<int> &p , int q){ if(query[q].first == 0)return GetLig(p,query[q].second); if(query[q].first == 1)return GetHea(p,query[q].second); if(query[q].first == 2)return GetMed(p,query[q].second); return GetNexLig(p,query[q].second); } int build(vector<int> p , int pos){ if(p.size() <= 1){ b[++nTime][0] = -1; // assert(p.size()); a[nTime] = (p.size() ? p[0] : 0); return nTime; } for(int i = 0 ; i < (int)query.size() ; ++i){ auto tmp = Get(p , i); int cnt = 0; for(int j = 0 ; j < 3 ; ++j){ cnt += (tmp[j].size() <= lim[pos]); } if(cnt < 3)continue; bool ok = 1; int tmpb[3]; for(int j = 0 ; j < 3 ; ++j){ int tmp1 = build(tmp[j],pos+1); if(!tmp1){ ok = 0; break; }; tmpb[j] = tmp1; } if(ok){ ++nTime; a[nTime] = i; for(int j = 0 ; j < 3 ; ++j)b[nTime][j] = tmpb[j]; return nTime; } } return 0; } void go(int x){ if(b[x][0] == -1){ int *ans = new int[6]; for(int i = 0; i < 6; i++) ans[perm[a[x]][i]] = i + 1; #ifndef LOCAL answer(ans); #endif // LOCAL return; } auto q = query[a[x]]; int id; if(q.first == 0)id = getLightest(q.second[0]+1,q.second[1]+1,q.second[2]+1); else if(q.first == 1)id = getHeaviest(q.second[0]+1,q.second[1]+1,q.second[2]+1); else if(q.first == 2)id = getMedian(q.second[0]+1,q.second[1]+1,q.second[2]+1); else id = getNextLightest(q.second[0]+1,q.second[1]+1,q.second[2]+1,q.second[3]+1); --id; for(int i = 0 ; i < 3 ; ++i){ if(q.second[i] == id){ go(b[x][i]); return; } } } void init(int T) { vector<int> tmp(6);iota(tmp.begin(),tmp.end(),0); do{ perm.pb(tmp); }while(next_permutation(tmp.begin(),tmp.end())); p.resize(perm.size());iota(p.begin(),p.end(),0); for(int i = 0 ; i < (1 << 6) ; ++i){ if(__builtin_popcount(i) == 3){ vector<int> tmp; for(int j = 0 ; j < 6 ; ++j){ if(i & (1 << j))tmp.pb(j); } for(int j = 0 ; j < 3 ; ++j){ query.pb(mp(j,tmp)); } for(int j = 0 ; j < 6; ++j){ auto tmp1 = tmp;tmp1.pb(j); query.pb(mp(3,tmp1)); } } } root = build(p,0); } void orderCoins() { go(root); } #ifdef LOCAL int main(){ init(0); } #endif

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

scales.cpp: In function 'std::vector<std::vector<int> > GetLig(std::vector<int>&, std::vector<int>&)':
scales.cpp:18:60: warning: declaration of 'a' shadows a global declaration [-Wshadow]
 vector<vector<int>> GetLig(vector<int> & p , vector<int> &a){
                                                            ^
scales.cpp:13:5: note: shadowed declaration is here
 int a[maxn] , b[maxn][3];
     ^
scales.cpp:18:60: warning: declaration of 'p' shadows a global declaration [-Wshadow]
 vector<vector<int>> GetLig(vector<int> & p , vector<int> &a){
                                                            ^
scales.cpp:11:13: note: shadowed declaration is here
 vector<int> p;
             ^
scales.cpp: In function 'std::vector<std::vector<int> > GetHea(std::vector<int>&, std::vector<int>&)':
scales.cpp:30:60: warning: declaration of 'a' shadows a global declaration [-Wshadow]
 vector<vector<int>> GetHea(vector<int> & p , vector<int> &a){
                                                            ^
scales.cpp:13:5: note: shadowed declaration is here
 int a[maxn] , b[maxn][3];
     ^
scales.cpp:30:60: warning: declaration of 'p' shadows a global declaration [-Wshadow]
 vector<vector<int>> GetHea(vector<int> & p , vector<int> &a){
                                                            ^
scales.cpp:11:13: note: shadowed declaration is here
 vector<int> p;
             ^
scales.cpp: In function 'std::vector<std::vector<int> > GetMed(std::vector<int>&, std::vector<int>&)':
scales.cpp:42:60: warning: declaration of 'a' shadows a global declaration [-Wshadow]
 vector<vector<int>> GetMed(vector<int> & p , vector<int> &a){
                                                            ^
scales.cpp:13:5: note: shadowed declaration is here
 int a[maxn] , b[maxn][3];
     ^
scales.cpp:42:60: warning: declaration of 'p' shadows a global declaration [-Wshadow]
 vector<vector<int>> GetMed(vector<int> & p , vector<int> &a){
                                                            ^
scales.cpp:11:13: note: shadowed declaration is here
 vector<int> p;
             ^
scales.cpp: In function 'std::vector<std::vector<int> > GetNexLig(std::vector<int>&, std::vector<int>&)':
scales.cpp:54:63: warning: declaration of 'a' shadows a global declaration [-Wshadow]
 vector<vector<int>> GetNexLig(vector<int> & p , vector<int> &a){
                                                               ^
scales.cpp:13:5: note: shadowed declaration is here
 int a[maxn] , b[maxn][3];
     ^
scales.cpp:54:63: warning: declaration of 'p' shadows a global declaration [-Wshadow]
 vector<vector<int>> GetNexLig(vector<int> & p , vector<int> &a){
                                                               ^
scales.cpp:11:13: note: shadowed declaration is here
 vector<int> p;
             ^
scales.cpp: In function 'std::vector<std::vector<int> > Get(std::vector<int>&, int)':
scales.cpp:72:47: warning: declaration of 'p' shadows a global declaration [-Wshadow]
 vector<vector<int>> Get(vector<int> &p , int q){
                                               ^
scales.cpp:11:13: note: shadowed declaration is here
 vector<int> p;
             ^
scales.cpp: In function 'int build(std::vector<int>, int)':
scales.cpp:79:34: warning: declaration of 'p' shadows a global declaration [-Wshadow]
 int build(vector<int> p , int pos){
                                  ^
scales.cpp:11:13: note: shadowed declaration is here
 vector<int> p;
             ^
scales.cpp:90:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             cnt += (tmp[j].size() <= lim[pos]);
scales.cpp: In function 'void init(int)':
scales.cpp:145:25: warning: declaration of 'tmp' shadows a previous local [-Wshadow]
             vector<int> tmp;
                         ^~~
scales.cpp:138:17: note: shadowed declaration is here
     vector<int> tmp(6);iota(tmp.begin(),tmp.end(),0);
                 ^~~
scales.cpp:137:15: warning: unused parameter 'T' [-Wunused-parameter]
 void init(int T) {
               ^
#Verdict Execution timeMemoryGrader output
Fetching results...