#include <bits/stdc++.h>
#include "library.h"
using namespace std;
bool vis[10000];
vector <int> P, Q;
int size;
void print(vector <int> &M) {
for(auto i : M) {
cout << i << " ";
}
cout << endl;
}
int query(vector <int> &v) {
bool good = false;
for(int i = 0; i < size; i++) {
if(v[i] == 1) {
good = true;
break;
}
}
return good ? Query(v) : 0;
}
bool goodSet(vector <int> &v) {
vector <int> com (size);
for(int i = 0; i < size; i++) {
if(vis[i]) com[i] = 1;
else com[i] = v[i] ^ 1;
}
int p = query(v);
int q = query(com);
return (p - 1) != q;
}
bool adjacent(int p, int q) {
vector <int> v (size);
v[p] = 1;
v[q] = 1;
return query(v) == 1;
}
bool goodSet(int p, int q, vector <int> &v) {
vector <int> shit (size);
for(int i = 0; i < size; i++) shit[i] = vis[i];
for(int i = p; i <= q; i++) shit[v[i]] = 1;
return goodSet(shit);
}
int search(int b, int e, vector <int> &v) {
if(b == e) {
return b;
}
int m = (b + e) >> 1;
if(goodSet(b, m, v)) return search(b, m, v);
else return search(m + 1, e, v);
}
void Solve(int N)
{
size = N;
vector<int> M(N);
for(int i = 0; i < size; i++) {
M[i] = i;
}
memset(vis, false, sizeof vis);
vector <int> H (size);
fill(H.begin(), H.end(), 1);
for(int i = 0; i < size; i++) {
H[i] = 0;
if(query(H) == 1) {
vis[i] = true;
M.erase(find(M.begin(), M.end(), i));
if(P.empty()) P.push_back(i);
else Q.push_back(i);
}
H[i] = 1;
}
while(P.size() + Q.size() < N) {
int can = search(0, M.size() - 1, M);
int val = M[can];
if (adjacent(P.back(), val)) P.push_back(val);
else Q.push_back(val);
M.erase(M.begin() + can);
vis[val] = true;
}
reverse(Q.begin(), Q.end());
vector<int> res(N);
for(int i = 0; i < P.size(); i++) {
res[i] = P[i] + 1;
}
for(int i = 0; i < Q.size(); i++) {
res[i + P.size()] = Q[i] + 1;
}
Answer(res);
}
Compilation message
library.cpp: In function 'void Solve(int)':
library.cpp:76:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(P.size() + Q.size() < N) {
~~~~~~~~~~~~~~~~~~~~^~~
library.cpp:86:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < P.size(); i++) {
~~^~~~~~~~~~
library.cpp:89:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < Q.size(); i++) {
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
252 KB |
Output is correct |
2 |
Correct |
42 ms |
308 KB |
Output is correct |
3 |
Correct |
43 ms |
560 KB |
Output is correct |
4 |
Correct |
44 ms |
560 KB |
Output is correct |
5 |
Correct |
51 ms |
560 KB |
Output is correct |
6 |
Correct |
47 ms |
560 KB |
Output is correct |
7 |
Correct |
41 ms |
560 KB |
Output is correct |
8 |
Correct |
48 ms |
604 KB |
Output is correct |
9 |
Correct |
51 ms |
604 KB |
Output is correct |
10 |
Correct |
28 ms |
604 KB |
Output is correct |
11 |
Runtime error |
2 ms |
608 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
252 KB |
Output is correct |
2 |
Correct |
42 ms |
308 KB |
Output is correct |
3 |
Correct |
43 ms |
560 KB |
Output is correct |
4 |
Correct |
44 ms |
560 KB |
Output is correct |
5 |
Correct |
51 ms |
560 KB |
Output is correct |
6 |
Correct |
47 ms |
560 KB |
Output is correct |
7 |
Correct |
41 ms |
560 KB |
Output is correct |
8 |
Correct |
48 ms |
604 KB |
Output is correct |
9 |
Correct |
51 ms |
604 KB |
Output is correct |
10 |
Correct |
28 ms |
604 KB |
Output is correct |
11 |
Runtime error |
2 ms |
608 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |