Submission #589692

# Submission time Handle Problem Language Result Execution time Memory
589692 2022-07-05T06:39:11 Z 박상훈(#8406) Lokahian Rampart (FXCUP3_lokahia) C++17
13 / 100
1103 ms 169736 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];

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){
            if (cnt>=2) break;
            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;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 792 KB Correct
2 Correct 1 ms 784 KB Correct
3 Correct 12 ms 1396 KB Correct
4 Correct 53 ms 18304 KB Correct
5 Correct 60 ms 13588 KB Correct
6 Correct 284 ms 102080 KB Correct
7 Correct 302 ms 104968 KB Correct
8 Correct 308 ms 169736 KB Correct
9 Correct 289 ms 108476 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 792 KB Correct
2 Correct 1 ms 784 KB Correct
3 Correct 12 ms 1396 KB Correct
4 Correct 53 ms 18304 KB Correct
5 Correct 60 ms 13588 KB Correct
6 Correct 284 ms 102080 KB Correct
7 Correct 302 ms 104968 KB Correct
8 Correct 308 ms 169736 KB Correct
9 Correct 289 ms 108476 KB Correct
10 Partially correct 778 ms 53680 KB Partially correct : C/MN = 1.550
11 Partially correct 44 ms 4928 KB Partially correct : C/MN = 1.312
12 Partially correct 241 ms 2828 KB Partially correct : C/MN = 1.467
13 Partially correct 4 ms 924 KB Partially correct : C/MN = 1.417
14 Partially correct 2 ms 588 KB Partially correct : C/MN = 1.333
15 Partially correct 2 ms 652 KB Partially correct : C/MN = 1.100
16 Partially correct 1 ms 648 KB Partially correct : C/MN = 1.250
17 Correct 2 ms 644 KB Correct
18 Correct 2 ms 648 KB Correct
19 Partially correct 1103 ms 119396 KB Partially correct : C/MN = 1.440
20 Correct 2 ms 796 KB Correct
21 Partially correct 1 ms 784 KB Partially correct : C/MN = 1.460
22 Runtime error 1 ms 340 KB Execution failed because the return code was nonzero
23 Halted 0 ms 0 KB -