제출 #198487

#제출 시각아이디문제언어결과실행 시간메모리
198487SuperJava자동 인형 (IOI18_doll)C++17
16 / 100
122 ms14036 KiB
#include "doll.h" #include <vector> #include <utility> #include <iostream> #include <algorithm> #define sz(A) int(size(A)) using namespace std; vector<int> adj[200005]; vector<int> v = {2,4,8,16,32,64,128,256,512,1024,2048, 4096,8192,16384,32768,65536,131072, 262144}; int dig(int x){ int ans = 0; while(x != 1){ x /= 2; ans++; } return ans; } void create_circuit(int M, vector<int> A) { for(int i = 0; i < sz(A)-1; i++){ adj[A[i]].push_back(A[i+1]); } adj[A[sz(A)-1]].push_back(0); vector<int> C(M+1); C[0] = A[0]; vector<int> X,Y; for(int i = 1; i <= M; i++){ int w = sz(adj[i]); if(w == 0) continue; if(w == 1){ C[i] = adj[i][0]; continue; } if(w == 2){ C[i] = -(sz(X)+1); X.push_back(adj[i][0]); Y.push_back(adj[i][1]); continue; } if((w&(w-1))){ C[i] = -(sz(X)+1); int fulen = *lower_bound(v.begin(), v.end(),w); vector<pair<int,int>> news(fulen-1); for(int j = 0; j < fulen/2-1; j++){ news[j].first = -(j+1)*2-sz(X); news[j].second = -(j+1)*2-sz(X)-1; } int digits = dig(fulen); vector<int> toadd(w); for(int j = 0; j < w; j++){ toadd[j] = adj[i][j]; } vector<int> qw; for(int j = 0; j < fulen; j++){ int res = 0; for(int k = 0; k < digits; k++){ res += (1<<k)*((j&(1<<(digits-k-1))) > 0); } qw.push_back(res); } for(int j = 0; j < fulen-w; j++){ if(j&1){ news[j+fulen/2-1].second = -(sz(X)+1); }else{ news[j+fulen/2-1].first = -(sz(X)+1); } } vector<pair<int,int>> ss; for(int j = fulen-w; j < fulen; j++){ ss.push_back({qw[j],j}); } sort(ss.begin(), ss.end()); for(int j = 0; j < w; j++){ if(ss[j].second&1){ news[(ss[j].second/2+fulen/2-1)].second = toadd[j]; }else{ news[(ss[j].second/2+fulen/2-1)].first = toadd[j]; } } /*for(int j = 0; j < sz(news); j++){ cout << news[j].first << " " << news[j].second << endl; }*/ for(int j = 0; j < fulen-1; j++){ X.push_back(news[j].first); Y.push_back(news[j].second); } }else{ C[i] = -(sz(X)+1); int fulen = *lower_bound(v.begin(), v.end(),w); vector<pair<int,int>> news(fulen-1); for(int j = 0; j < fulen/2-1; j++){ news[j].first = -(j+1)*2-sz(X); news[j].second = -(j+1)*2-sz(X)-1; } int digits = dig(fulen); vector<int> toadd(fulen); for(int j = 0; j < w; j++){ toadd[j] = adj[i][j]; } for(int j = 0; j < fulen; j++){ int res = 0; for(int k = 0; k < digits; k++){ res += (1<<k)*((j&(1<<(digits-k-1))) > 0); } if(res&1){ news[res/2+fulen/2-1].second = toadd[j]; }else{ news[res/2+fulen/2-1].first = toadd[j]; } } for(int j = 0; j < fulen-1; j++){ X.push_back(news[j].first); Y.push_back(news[j].second); } } } answer(C,X,Y); }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...