#include "coloring.h"
#include <cstdio>
int next[111];
int n;
int k;
int ccolor = 0;
int cgetcolor = 0;
void ColorX(int x) {
//printf("Color %d\n", x);
ccolor++;
return Color(x);
}
int GetColorX(int x) {
cgetcolor++;
//printf("GetColor %d\n", x);
return GetColor(x);
}
int find_prev(int x) {
//printf("find_prev %d\n", x);
int rem = n - k - 1;
if (rem == 0) {
return 1;
}
int mn = 1;
int mx = n;
while(1) {
if (rem == 1)
break;
int i;
int c = rem / 2;
int cc = c;
for(i = mn;;i++) {
if (next[i] == -1 && i != x) {
ColorX(i);
c--;
if (c == 0) {
break;
}
}
}
int exist = GetColorX(x);
if (exist) {
mn = i+1;
rem = rem - cc;
}
else {
mx = i;
rem = cc;
}
}
for (int i = mn; i <= mx; i++) {
if (next[i] == -1 && i != x) {
return i;
}
}
return 0;
}
void ColoringSame(int N) {
n = N;
k = 0;
for(int i=1;i<=N;i++){
next[i] = -1;
}
next[1] = 0;
int pr;
int nx = 1;
int A = 0;
int last;
for(int i=0;;i++){
pr = find_prev(nx);
A++;
last = pr;
next[pr] = nx;
//printf("%d -> %d\n", pr, nx);
k++;
nx = pr;
if (nx == 1)break;
if (cgetcolor >=194)break;
}
//printf("Color: %d\nGetColor: %d\n", ccolor, cgetcolor);
ColorX(1);
for (int i=0;i<n - A - 1;i++){
for(int j=1;j<=n;j++) {
if (next[j] == -1) {
ColorX(j);
if (ccolor == 7250)break;
}
}
if (ccolor == 7250)break;
}
for(;;) {
if (next[last] == 1) break;
ColorX(last);
last = next[last];
}
//printf("Color: %d\nGetColor: %d\n", ccolor, cgetcolor);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1124 KB |
Output is correct |
2 |
Correct |
0 ms |
1124 KB |
Output is correct |
3 |
Correct |
0 ms |
1124 KB |
Output is correct |
4 |
Correct |
0 ms |
1124 KB |
Output is correct |
5 |
Correct |
0 ms |
1124 KB |
Output is correct |
6 |
Correct |
0 ms |
1124 KB |
Output is correct |
7 |
Correct |
0 ms |
1124 KB |
Output is correct |
8 |
Correct |
0 ms |
1124 KB |
Output is correct |
9 |
Correct |
0 ms |
1124 KB |
Output is correct |
10 |
Correct |
0 ms |
1124 KB |
Output is correct |
11 |
Correct |
0 ms |
1124 KB |
Output is correct |
12 |
Correct |
0 ms |
1124 KB |
Output is correct |
13 |
Correct |
0 ms |
1124 KB |
Output is correct |
14 |
Correct |
0 ms |
1124 KB |
Output is correct |
15 |
Correct |
0 ms |
1124 KB |
Output is correct |
16 |
Correct |
0 ms |
1124 KB |
Output is correct |
17 |
Correct |
0 ms |
1124 KB |
Output is correct |
18 |
Correct |
0 ms |
1124 KB |
Output is correct |
19 |
Correct |
0 ms |
1124 KB |
Output is correct |
20 |
Correct |
0 ms |
1124 KB |
Output is correct |
21 |
Correct |
0 ms |
1124 KB |
Output is correct |
22 |
Correct |
0 ms |
1124 KB |
Output is correct |
23 |
Correct |
0 ms |
1124 KB |
Output is correct |
24 |
Correct |
0 ms |
1124 KB |
Output is correct |
25 |
Correct |
0 ms |
1124 KB |
Output is correct |