이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL
#define hashA 1257958787
#define hashB 1539500609
#define endl "\n"
bool was[1000005];
int getnext(int x, int cn) {
if(x == 0) {
return cn/2;
}
int ls = (x & (-x));
int stays = ls;
int curr = ls;
while(x&(curr*2)) {
stays+= curr*2;
curr*=2;
}
bool did = false;
bool was = false;
for(int pw = 20; pw >= 0; pw--) {
if((1<<pw) <= stays) {
break;
}
if((1<<pw)+stays <= cn && (x&(1<<pw)) == 0 && was) {
x= stays+(1<<pw);
did = true;
break;
}
if(x&(1<<pw)) {
was = true;
}
}
if(!was) {
for(int pw = 20; pw >= 0; pw--) {
if((1<<pw) <= ls) {
break;
}
if((1<<pw)+stays <= cn && (x&(1<<pw)) == 0) {
x= stays+(1<<pw);
did = true;
break;
}
}
}
if(!did) {
x = ls/2;
}
return x;
}
vector<pair<int,int> > getorder(int cn) {
vector<pair<int,int> > ord;
int currpos = 0;
for(int i = 0; i < cn; i++) {
ord.push_back({currpos,0});
// cout << currpos << endl;
currpos = getnext(currpos,cn);
}
for(int i = 0; i < cn; i++) {
ord.push_back({ord[i].first,1});
}
return ord;
}
void create_circuit(int m, std::vector<int> A) {
vector<int> C(m+1,-1);
int n = A.size();
int cn = 1;
int ends = 1;
while(2*ends < n+1) {
cn*=2;
cn++;
ends*= 2;
}
vector<int> X (cn);
vector<int> Y (cn);
for(int i = 0; (i+1)*2 < cn; i++) {
X[i] = -(i*2+2);
Y[i] = -(i*2+3);
}
int ind = 0;
vector<pair<int,int> > ord = getorder(ends);
//cout << ends << " " << ord.size() << endl;
for(int i = 0; i < 2*ends; i++) {
// cout << ord[i].first << endl;
if(ord[i].second == 0) {
if(ind < n) {
X[ord[i].first+cn/2] = A[ind++];
} else {
X[ord[i].first+cn/2] = -1;
}
} else {
if(ind < n) {
Y[ord[i].first+cn/2] = A[ind++];
} else {
Y[ord[i].first+cn/2] = -1;
}
}
}
Y[cn-1] = 0;
/*for(int i = 0; i < cn; i++) {
cout << X[i] << " " << Y[i] << endl;
}*/
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... |