#include "sungjin.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static int dx[5] = {0, 0, 0, 1, -1}, dy[5] = {0, 1, -1, 0, 0};
static int a[1010][1010], n, m;
static bool iswall[1010][1010][5];
static void dfs0(int i, int j){
a[i][j] = -1;
for (int k=1;k<=4;k++){
int nx = i+dx[k], ny = j+dy[k];
if (nx<0 || nx>n+1 || ny<0 || ny>m+1) continue;
if (a[nx][ny]!=-1 && !iswall[nx][ny][((k-1)^1)+1]) dfs0(nx, ny);
}
}
static void dfs(int i, int j, int c){
a[i][j] = c;
for (int k=1;k<=4;k++){
int nx = i+dx[k], ny = j+dy[k];
if (nx<=0 || nx>=n+1 || ny<=0 || ny>=m+1) continue;
if (a[nx][ny]==0) dfs(nx, ny, c);
}
}
void Init(int N, int M, int W, int R[], int C[], int dir[]) {
//return;
n = N, m = M;
//for (int i=0;i<=N+1;i++) fill(a[i], a[i]+M+2, -1);
//for (int i=1;i<=N;i++) fill(a[i]+1, a[i]+M+1, 0);
for (int i=0;i<W;i++){
iswall[R[i]][C[i]][dir[i]] = 1;
//a[R[i]+dx[dir[i]]][C[i]+dy[dir[i]]] = -1;
}
dfs0(0, 0);
int cnt = 1;
for (int i=1;i<=N;i++){
for (int j=1;j<=M;j++) if (a[i][j]==0){
dfs(i, j, cnt);
cnt++;
}
}
/*for (int i=1;i<=N;i++){
for (int j=1;j<=M;j++) if (a[i][j]>0){
for (int k=1;k<=4;k++){
int nx = i+dx[k], ny = j+dy[k];
if (a[nx][ny]==-1 && !iswall[i][j][k]) no[a[i][j]] = 1;
}
}
}*/
/*for (int i=1;i<=N;i++){
for (int j=1;j<=M;j++) printf("%d ", a[i][j]);
printf("\n");
}*/
}
int WereSameTerritory(int R1, int C1, int R2, int C2) {
//return 0;
if (a[R1][C1]>0 && a[R1][C1]==a[R2][C2]) return 1;
return 0;
}
#include "dowoon.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}, n, m;
static int my_ans[1010][1010][4];
static bool visited[1010][1010];
static int is_edge(int x, int y, int k){
int nx = x + dx[k], ny = y + dy[k];
if (nx<=0 || nx>n) return 0;
if (ny<=0 || ny>m) return 0;
if (my_ans[x][y][k]>=0) return my_ans[x][y][k];
int ret = Ask(x, y, nx, ny);
my_ans[x][y][k] = ret;
my_ans[nx][ny][k^1] = ret;
return ret;
}
static int cnt;
static void dfs(int i, int j){
visited[i][j] = 1;
cnt++;
for (int k=0;k<4;k++){
int nx = i+dx[k], ny = j+dy[k];
if (!visited[nx][ny] && is_edge(i, j, k)) dfs(nx, ny);
}
}
int Guess(int N, int M) {
//return 0;
n = N, m = M;
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++) fill(my_ans[i][j], my_ans[i][j]+4, -1);
}
int ans = 0;
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++) if (!visited[i][j]){
cnt = 0;
dfs(i, j);
ans = max(ans, cnt);
}
}
if (ans*2 > n*m) return 1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
792 KB |
Correct |
2 |
Correct |
1 ms |
784 KB |
Correct |
3 |
Correct |
11 ms |
1276 KB |
Correct |
4 |
Correct |
59 ms |
17888 KB |
Correct |
5 |
Correct |
56 ms |
12860 KB |
Correct |
6 |
Correct |
252 ms |
100916 KB |
Correct |
7 |
Correct |
224 ms |
103696 KB |
Correct |
8 |
Correct |
305 ms |
169772 KB |
Correct |
9 |
Correct |
272 ms |
100100 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
792 KB |
Correct |
2 |
Correct |
1 ms |
784 KB |
Correct |
3 |
Correct |
11 ms |
1276 KB |
Correct |
4 |
Correct |
59 ms |
17888 KB |
Correct |
5 |
Correct |
56 ms |
12860 KB |
Correct |
6 |
Correct |
252 ms |
100916 KB |
Correct |
7 |
Correct |
224 ms |
103696 KB |
Correct |
8 |
Correct |
305 ms |
169772 KB |
Correct |
9 |
Correct |
272 ms |
100100 KB |
Correct |
10 |
Partially correct |
580 ms |
53616 KB |
Partially correct : C/MN = 1.550 |
11 |
Partially correct |
37 ms |
4988 KB |
Partially correct : C/MN = 1.312 |
12 |
Partially correct |
23 ms |
2856 KB |
Partially correct : C/MN = 1.467 |
13 |
Partially correct |
4 ms |
928 KB |
Partially correct : C/MN = 1.417 |
14 |
Partially correct |
2 ms |
660 KB |
Partially correct : C/MN = 1.333 |
15 |
Partially correct |
2 ms |
648 KB |
Partially correct : C/MN = 1.100 |
16 |
Partially correct |
0 ms |
652 KB |
Partially correct : C/MN = 1.250 |
17 |
Correct |
1 ms |
660 KB |
Correct |
18 |
Correct |
0 ms |
656 KB |
Correct |
19 |
Partially correct |
964 ms |
105964 KB |
Partially correct : C/MN = 1.440 |
20 |
Correct |
1 ms |
788 KB |
Correct |
21 |
Partially correct |
1 ms |
784 KB |
Partially correct : C/MN = 1.460 |
22 |
Partially correct |
1 ms |
780 KB |
Partially correct : C/MN = 1.480 |
23 |
Partially correct |
3 ms |
964 KB |
Partially correct : C/MN = 1.038 |
24 |
Partially correct |
13 ms |
16304 KB |
Partially correct : C/MN = 1.039 |
25 |
Partially correct |
7 ms |
3260 KB |
Partially correct : C/MN = 1.558 |
26 |
Partially correct |
25 ms |
4712 KB |
Partially correct : C/MN = 1.195 |
27 |
Partially correct |
35 ms |
5944 KB |
Partially correct : C/MN = 1.399 |
28 |
Partially correct |
39 ms |
4552 KB |
Partially correct : C/MN = 1.131 |
29 |
Partially correct |
53 ms |
20656 KB |
Partially correct : C/MN = 1.112 |
30 |
Partially correct |
71 ms |
20544 KB |
Partially correct : C/MN = 1.166 |
31 |
Partially correct |
251 ms |
138028 KB |
Partially correct : C/MN = 1.153 |
32 |
Partially correct |
299 ms |
121020 KB |
Partially correct : C/MN = 1.284 |
33 |
Partially correct |
248 ms |
77688 KB |
Partially correct : C/MN = 1.397 |
34 |
Partially correct |
269 ms |
117088 KB |
Partially correct : C/MN = 1.298 |
35 |
Partially correct |
294 ms |
104652 KB |
Partially correct : C/MN = 1.998 |
36 |
Correct |
280 ms |
196516 KB |
Correct |
37 |
Partially correct |
268 ms |
30792 KB |
Partially correct : C/MN = 1.630 |
38 |
Partially correct |
275 ms |
30496 KB |
Partially correct : C/MN = 1.778 |
39 |
Partially correct |
208 ms |
26164 KB |
Partially correct : C/MN = 1.239 |
40 |
Partially correct |
192 ms |
26912 KB |
Partially correct : C/MN = 1.292 |
41 |
Partially correct |
274 ms |
88360 KB |
Partially correct : C/MN = 1.204 |
42 |
Partially correct |
269 ms |
63848 KB |
Partially correct : C/MN = 1.998 |
43 |
Partially correct |
251 ms |
54512 KB |
Partially correct : C/MN = 1.498 |
44 |
Partially correct |
106 ms |
13264 KB |
Partially correct : C/MN = 1.600 |
45 |
Partially correct |
127 ms |
13300 KB |
Partially correct : C/MN = 1.600 |
46 |
Partially correct |
311 ms |
30660 KB |
Partially correct : C/MN = 1.499 |