Submission #827459

#TimeUsernameProblemLanguageResultExecution timeMemory
827459SupersonicScales (IOI15_scales)C++14
46.82 / 100
76 ms308 KiB
#include "scales.h" #include <bits/stdc++.h> using namespace std; set<int> gt[7]; set<int> lt[7]; set<int> gtbk[7]; set<int> ltbk[7]; int score(){ int sc=0; for(int i=1;i<=6;i++){ sc+=(int)(gt[i].size()+lt[i].size()); } //cerr<<sc<<endl; return sc; } void backup(){ for(int i=1;i<=6;i++){ gtbk[i]=gt[i]; ltbk[i]=lt[i]; } } void restore(){ for(int i=1;i<=6;i++){ gt[i]=gtbk[i]; lt[i]=ltbk[i]; } } void clean(){ for(int i=1;i<=6;i++){ gt[i].clear(); lt[i].clear(); } backup(); } void dbg(){ for(int i=1;i<=6;i++){ cerr<<i<<" is greater than ";for(auto j:gt[i])cerr<<j<<' ';cerr<<endl; }cerr<<endl; for(int i=1;i<=6;i++){ cerr<<i<<" is less than ";for(auto j:lt[i])cerr<<j<<' ';cerr<<endl; }cerr<<endl; } vector<int> done(){ //dbg(); vector<pair<int,int>> ix; bool chk[6]={0,0,0,0,0,0}; for(int i=1;i<=6;i++){ ix.push_back({lt[i].size(),i}); chk[lt[i].size()]=1; } if(!(chk[0]&&chk[1]&&chk[2]&&chk[3]&&chk[4]&&chk[5]))return {-1}; sort(ix.rbegin(),ix.rend()); vector<int> r; for(auto i:ix)r.push_back(i.second); return r; } void update(int a,int b){ if(a==b)return; //cerr<<a<<' '<<b<<endl; gt[b].insert(a); lt[a].insert(b); for(auto i:gt[a]){gt[b].insert(i);lt[i].insert(b);} for(auto i:lt[b]){lt[a].insert(i);gt[i].insert(a);} //for(int i=1;i<=6;i++)cerr<<gt[i].size()<<' ';cerr<<endl; } void init(int T) { T++; } void orderCoins() { clean(); while(true){ // lightest = 1, heaviest = 2 vector<int> bop;int bopt=-1;int bc=-1; // lightest for(int a=1;a<=6;a++)for(int b=1;b<=6;b++)for(int c=1;c<=6;c++){ if(a==b||a==c||b==c)continue; int e=1000000; backup();update(a,b);update(a,c);e=min(e,score());restore(); backup();update(b,a);update(b,c);e=min(e,score());restore(); backup();update(c,a);update(c,b);e=min(e,score());restore(); if(e>bc){bc=e;bopt=1;bop={a,b,c};} } for(int a=1;a<=6;a++)for(int b=1;b<=6;b++)for(int c=1;c<=6;c++){ if(a==b||a==c||b==c)continue; int e=1000000; backup();update(b,a);update(c,a);e=min(e,score());restore(); backup();update(a,b);update(c,b);e=min(e,score());restore(); backup();update(a,c);update(b,c);e=min(e,score());restore(); if(e>bc){bc=e;bopt=2;bop={a,b,c};} } if(bopt==-1){cerr<<"ERROR"<<endl;exit(1);} if(bopt==1){ //cerr<<"LIGHT: "<<bop[0]<<' '<<bop[1]<<' '<<bop[2]<<endl; //cerr<<bc<<endl; int r=getLightest(bop[0],bop[1],bop[2]); update(r,bop[0]);update(r,bop[1]);update(r,bop[2]); } if(bopt==2){ //cerr<<"HEAVY: "<<bop[0]<<' '<<bop[1]<<' '<<bop[2]<<endl; //cerr<<bc<<endl; int r=getHeaviest(bop[0],bop[1],bop[2]); update(bop[0],r);update(bop[1],r);update(bop[2],r); } vector<int> rr=done(); if(rr[0]>0){ int ra[6]={rr[0],rr[1],rr[2],rr[3],rr[4],rr[5]}; answer(ra); return; } //else clean(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...