이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <vector>
#include "library.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int maxn = 1100;
vector<int>adj[maxn];
vector<int>M;
int n;
bool forb[maxn];
int preQuery(vector<int>M) {
int br = 0;
for(int i:M) {
if(i == 1) br++;
}
if(br == 0) return 0;
else return Query(M);
}
int find_neighbour(int x, int l=1, int r=n) {
if(l == r) {
// check if X is connected to L or not
if(adj[x].size() == 1) {
if(l == adj[x][0]) return -1;
}
M[l-1] = M[x-1] = 1;
int curr = preQuery(M);
M[l-1] = M[x-1] = 0;
if(curr == 1) return l;
else return -1;
}
int mid = (l + r) /2;
for(int i=l-1;i<=mid-1;i++) {
M[i] = 1;
}
for(int i:adj[x]) {
M[i-1] = 0;
}
M[x-1] = 0;
int Without = preQuery(M);
M[x-1] = 1;
int With = preQuery(M);
M[x-1] = 0;
for(int i=l-1;i<=mid-1;i++) {
M[i] = 0;
}
if(With == Without) {
return find_neighbour(x, l, mid);
}
else if(With < Without) {
return find_neighbour(x, l, mid);
}
else {
return find_neighbour(x, mid+1, r);
}
}
void Solve(int N) {
n = N;
for(int i=0;i<N;i++) {
M.pb(0);
}
if(N == 1) {
vector<int>v;
v.pb(1);
Answer(v);
return;
}
int st = 1;
bool check = false;
for(int i=0;i<N;i++) {
if(check) continue;
int X = find_neighbour(st);
if(X == -1) {
// st is on corner
if(st == 1) {
check = true;
}
else {
st = 1;
}
}
else {
adj[st].pb(X);
adj[X].pb(st);
st = X;
}
}
/*for(int i=1;i<=n;i++) {
cout<<i<<": \n";
for(int j:adj[i]) {
cout<<j<<" ";
} cout<<"\n";
}*/
st = 1;
for(int i=1;i<=N;i++) {
if(adj[i].size() == 1) {
st = i;
break;
}
}
vector<int>v;
v.pb(st);
st = adj[st][0];
for(int i=0;i<N-1;i++) {
if(adj[st][0] == v.back()) {
v.pb(st);
st = adj[st][1];
}
else {
v.pb(st);
st = adj[st][0];
}
}
Answer(v);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |