Submission #589678

# Submission time Handle Problem Language Result Execution time Memory
589678 2022-07-05T06:18:05 Z 반딧불(#8407) Lokahian Rampart (FXCUP3_lokahia) C++17
0 / 100
1 ms 832 KB
#include "sungjin.h"
#include <bits/stdc++.h>

namespace {
    const int xx[]={0, 0, 1, -1};
    const int yy[]={1, -1, 0, 0};

    int n, m, k;
    int board[1002][1002];
    bool able[1002][1002];
    int num[1002][1002], numCnt;
}

void dfsAble(int x, int y){
    able[x][y] = 0;
    for(int d=0; d<4; d++){
        int tx = x+xx[d], ty = y+yy[d];
        if(tx<0 || ty<0 || tx>n+1 || ty>m+1 || !able[tx][ty]) continue;
        if(board[x][y] & (1<<d)) continue;
        if(board[tx][ty] & (1<<(d^1))) continue;
        dfsAble(tx, ty);
    }
}

void dfsGroup(int x, int y, int g){
    num[x][y] = g;
//    printf("%d %d: %d\n", x, y, g);
    for(int d=0; d<4; d++){
        int tx = x+xx[d], ty = y+yy[d];
        if(!able[tx][ty] || num[tx][ty]) continue;
        dfsGroup(tx, ty, g);
    }
}

void Init(int N, int M, int W, int R[], int C[], int D[]){
	n = N, m = M, k = W;
	for(int i=0; i<k; i++){
        D[i]--;
        int x = R[i], y = C[i], d = D[i];
        board[x][y] |= (1<<d);
	}
    for(int i=0; i<=n+1; i++) for(int j=0; j<=m+1; j++) able[i][j] = 1;
    dfsAble(0, 0);
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(!able[i][j] || num[i][j]) continue;
            dfsGroup(i, j, ++numCnt);
        }
    }
}

int WereSameTerritory(int R1, int C1, int R2, int C2) {
	if(!able[R1][C1] || !able[R1][C2] || num[R1][C1] != 1 && 1 != num[R2][C2]) return false;
	return true;
}
#include "dowoon.h"
#include <bits/stdc++.h>

using namespace std;

namespace {
    const int xx[]={0, 0, 1, -1};
    const int yy[]={1, -1, 0, 0};

    int n, m;
    int link[1002][1002][4];
    int visited[1002][1002];
    int ans;
    int cnt;
}

void dfs(int x, int y){
    visited[x][y] = 1;
    cnt++;
    for(int d=0; d<4; d++){
        int tx = x+xx[d], ty = y+yy[d];
        if(!link[x][y][d] || visited[tx][ty]) continue;
        dfs(tx, ty);
    }
}

int Guess(int N, int M){
    n = N, m = M;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(i<n) link[i][j][2] = link[i+1][j][3] = Ask(i, j, i+1, j);
            if(j<m) link[i][j][0] = link[i][j+1][1] = Ask(i, j, i, j+1);
        }
    }
    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);
            }
        }
    }
    return ans*2 > n*m;
}

Compilation message

sungjin.cpp: In function 'int WereSameTerritory(int, int, int, int)':
sungjin.cpp:53:56: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   53 |  if(!able[R1][C1] || !able[R1][C2] || num[R1][C1] != 1 && 1 != num[R2][C2]) return false;
      |                                       ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 832 KB Correct
2 Runtime error 1 ms 340 KB Execution failed because the return code was nonzero
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 832 KB Correct
2 Runtime error 1 ms 340 KB Execution failed because the return code was nonzero
3 Halted 0 ms 0 KB -