#include "chameleon.h"
#include <vector>
using namespace std;
namespace {
vector<int> edge[1001];
int vis[1001];
int clr[1001];
int p[1001];
} // namespace
void dfs(int x, int c,int stamp) {
if (vis[x] == stamp) return;
vis[x] = stamp;
clr[x] = c;
for (auto nxt : edge[x]) dfs(nxt, 3 - c, stamp);
}
int qry(vector<int> p,int self) {
if (p.empty()) return 1;
p.push_back(self);
return Query(p);
}
void Solve(int N) {
int NN = N + N;
vector<int> clr_set[3];
for (int i = 2; i <= NN; ++i) {
clr_set[2].clear(); clr_set[1].clear();
for (int j = 1; j < i; ++j) {
dfs(j, 1, i);
clr_set[clr[j]].push_back(j);
}
for (int j = 1; j <= 2; ++j) {
vector<int> &st = clr_set[j];
if (st.empty()) continue;
while (st.size() >= qry(st, i)) {
int l = 0, r = st.size() - 1;
int pick = 0;
while (l < r) {
int m = (l + r) >> 1;
//
vector<int> v(st.begin()+l, st.begin()+ m + 1);
if (qry(v, i) <= v.size()) {
//r = m - 1;
r = m;
//pick = m;
}
else
l = m + 1;
}
pick = l;
edge[st[pick]].push_back(i); edge[i].push_back(st[pick]);
st.assign(st.begin() + pick + 1, st.end());
}
}
}
for (int i = 1; i <= NN; ++i) {
for (auto x : edge[i]) p[i] += x;
}
for (int i = 1; i <= NN; ++i) {
if (edge[i].size() == 1) continue;
int to = -1;
for (int j = 0; j < edge[i].size() && to<0; ++j) { //pick
vector<int> v;
for (auto x : edge[i]) {
if (edge[i][j] == x) continue;
v.push_back(x);
}
if (qry(v, i) == 1) to = edge[i][j];
}
p[i] -= to;
p[to] -= i;
}
for (int i = 1; i <= NN; ++i) if (i < p[i]) Answer(i, p[i]);
}
Compilation message
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:36:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
36 | while (st.size() >= qry(st, i)) {
| ~~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | if (qry(v, i) <= v.size()) {
| ~~~~~~~~~~^~~~~~~~~~~
chameleon.cpp:64:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for (int j = 0; j < edge[i].size() && to<0; ++j) { //pick
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
32 ms |
384 KB |
Output is correct |
4 |
Correct |
32 ms |
384 KB |
Output is correct |
5 |
Correct |
28 ms |
384 KB |
Output is correct |
6 |
Correct |
28 ms |
384 KB |
Output is correct |
7 |
Correct |
33 ms |
384 KB |
Output is correct |
8 |
Correct |
32 ms |
384 KB |
Output is correct |
9 |
Correct |
28 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
360 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
360 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
53 ms |
464 KB |
Output is correct |
4 |
Correct |
55 ms |
512 KB |
Output is correct |
5 |
Correct |
51 ms |
384 KB |
Output is correct |
6 |
Correct |
60 ms |
384 KB |
Output is correct |
7 |
Correct |
61 ms |
384 KB |
Output is correct |
8 |
Correct |
64 ms |
384 KB |
Output is correct |
9 |
Correct |
52 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
32 ms |
384 KB |
Output is correct |
4 |
Correct |
32 ms |
384 KB |
Output is correct |
5 |
Correct |
28 ms |
384 KB |
Output is correct |
6 |
Correct |
28 ms |
384 KB |
Output is correct |
7 |
Correct |
33 ms |
384 KB |
Output is correct |
8 |
Correct |
32 ms |
384 KB |
Output is correct |
9 |
Correct |
28 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
360 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
53 ms |
464 KB |
Output is correct |
31 |
Correct |
55 ms |
512 KB |
Output is correct |
32 |
Correct |
51 ms |
384 KB |
Output is correct |
33 |
Correct |
60 ms |
384 KB |
Output is correct |
34 |
Correct |
61 ms |
384 KB |
Output is correct |
35 |
Correct |
64 ms |
384 KB |
Output is correct |
36 |
Correct |
52 ms |
384 KB |
Output is correct |
37 |
Correct |
61 ms |
384 KB |
Output is correct |
38 |
Correct |
32 ms |
384 KB |
Output is correct |
39 |
Correct |
67 ms |
384 KB |
Output is correct |
40 |
Correct |
60 ms |
504 KB |
Output is correct |
41 |
Correct |
61 ms |
468 KB |
Output is correct |
42 |
Correct |
28 ms |
420 KB |
Output is correct |
43 |
Correct |
53 ms |
384 KB |
Output is correct |
44 |
Correct |
63 ms |
384 KB |
Output is correct |
45 |
Correct |
73 ms |
384 KB |
Output is correct |