#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], no[1001000];
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 (a[nx][ny]==0) dfs(nx, ny, c);
}
}
void Init(int N, int M, int W, int R[], int C[], int dir[]) {
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) {
if (a[R1][C1]==a[R2][C2] && !no[a[R1][C1]]) return 1;
return 0;
}
#include "dowoon.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}, n, m;
int my_ans[1010][1010][4];
bool visited[1010][1010];
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;
}
int cnt;
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) {
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 |
0 ms |
792 KB |
Correct |
2 |
Runtime error |
0 ms |
340 KB |
Execution failed because the return code was nonzero |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
792 KB |
Correct |
2 |
Runtime error |
0 ms |
340 KB |
Execution failed because the return code was nonzero |
3 |
Halted |
0 ms |
0 KB |
- |