This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "doll.h"
#include <vector>
#include <utility>
#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+2)*2-sz(X);
}
int digits = dig(fulen);
vector<int> toadd(fulen);
for(int j = 0; j < w-1; j++){
toadd[j] = adj[i][j];
}
for(int j = w-1; j < fulen-1; j++){
toadd[j] = -(sz(X)+1);
}
toadd[fulen-1] = adj[i][w-1];
for(int j = 0; j < fulen; j++){
int res = 0;
for(int k = 0; k < digits; k++){
res += (1<<k)*((j&(digits-k)) > 0);
}
if(res&1){
news[res/2].second = toadd[j];
}else{
news[res/2].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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |