답안 #589677

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589677 2022-07-05T06:15:55 Z 박상훈(#8406) 로카히아 유적 (FXCUP3_lokahia) C++17
30 / 100
1042 ms 212084 KB
#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[]) {
    //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] && !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) {
    //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 792 KB Correct
3 Correct 11 ms 1316 KB Correct
4 Correct 57 ms 18200 KB Correct
5 Correct 59 ms 13564 KB Correct
6 Correct 238 ms 102176 KB Correct
7 Correct 244 ms 104968 KB Correct
8 Correct 329 ms 169832 KB Correct
9 Correct 281 ms 108460 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 792 KB Correct
2 Correct 1 ms 792 KB Correct
3 Correct 11 ms 1316 KB Correct
4 Correct 57 ms 18200 KB Correct
5 Correct 59 ms 13564 KB Correct
6 Correct 238 ms 102176 KB Correct
7 Correct 244 ms 104968 KB Correct
8 Correct 329 ms 169832 KB Correct
9 Correct 281 ms 108460 KB Correct
10 Partially correct 657 ms 53648 KB Partially correct : C/MN = 1.550
11 Partially correct 41 ms 4912 KB Partially correct : C/MN = 1.312
12 Partially correct 30 ms 2804 KB Partially correct : C/MN = 1.467
13 Partially correct 3 ms 928 KB Partially correct : C/MN = 1.417
14 Partially correct 2 ms 648 KB Partially correct : C/MN = 1.333
15 Partially correct 2 ms 652 KB Partially correct : C/MN = 1.100
16 Partially correct 2 ms 644 KB Partially correct : C/MN = 1.250
17 Correct 0 ms 648 KB Correct
18 Correct 0 ms 648 KB Correct
19 Partially correct 1042 ms 112632 KB Partially correct : C/MN = 1.440
20 Correct 2 ms 800 KB Correct
21 Partially correct 1 ms 824 KB Partially correct : C/MN = 1.460
22 Partially correct 3 ms 804 KB Partially correct : C/MN = 1.480
23 Partially correct 4 ms 1056 KB Partially correct : C/MN = 1.038
24 Partially correct 16 ms 16416 KB Partially correct : C/MN = 1.039
25 Partially correct 8 ms 3252 KB Partially correct : C/MN = 1.558
26 Partially correct 19 ms 4700 KB Partially correct : C/MN = 1.195
27 Partially correct 41 ms 6072 KB Partially correct : C/MN = 1.399
28 Partially correct 43 ms 4692 KB Partially correct : C/MN = 1.131
29 Partially correct 52 ms 20536 KB Partially correct : C/MN = 1.112
30 Partially correct 70 ms 20276 KB Partially correct : C/MN = 1.166
31 Partially correct 296 ms 133544 KB Partially correct : C/MN = 1.153
32 Partially correct 290 ms 126900 KB Partially correct : C/MN = 1.284
33 Partially correct 301 ms 78488 KB Partially correct : C/MN = 1.397
34 Partially correct 296 ms 123128 KB Partially correct : C/MN = 1.298
35 Partially correct 412 ms 104576 KB Partially correct : C/MN = 1.998
36 Correct 353 ms 212084 KB Correct
37 Partially correct 308 ms 30748 KB Partially correct : C/MN = 1.630
38 Partially correct 263 ms 30416 KB Partially correct : C/MN = 1.778
39 Partially correct 187 ms 26120 KB Partially correct : C/MN = 1.239
40 Partially correct 194 ms 26864 KB Partially correct : C/MN = 1.292
41 Partially correct 255 ms 88548 KB Partially correct : C/MN = 1.204
42 Partially correct 296 ms 63872 KB Partially correct : C/MN = 1.998
43 Partially correct 266 ms 54616 KB Partially correct : C/MN = 1.498
44 Partially correct 118 ms 13280 KB Partially correct : C/MN = 1.600
45 Partially correct 138 ms 13344 KB Partially correct : C/MN = 1.600
46 Partially correct 297 ms 35244 KB Partially correct : C/MN = 1.499