답안 #1054218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054218 2024-08-12T07:43:02 Z 정민찬(#11058) 무지개나라 (APIO17_rainbow) C++14
11 / 100
14 ms 2908 KB
#include "rainbow.h"
#include <bits/stdc++.h>

using namespace std;

int board[60][60];

void init(int R, int C, int sr, int sc, int M, char *S) {
    int x = sr, y = sc;
    board[x][y] = 1;
    for (int i=0; i<M; i++) {
        if (S[i] == 'N') x --;
        if (S[i] == 'S') x ++;
        if (S[i] == 'W') y --;
        if (S[i] == 'E') y ++;
        board[x][y] = 1;
    }
}

struct DisjointSet{
    vector<int> par;
    void init(int n) {
        par.resize(n);
        iota(par.begin(), par.end(), 0);
    }
    int Find(int x) {
        if (par[x] == x) return x;
        return par[x] = Find(par[x]);
    }
    void Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        par[y] = x;
    }
};

DisjointSet dsu;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int colour(int ar, int ac, int br, int bc) {
    dsu.init((br-ar+1) * (bc-ac+1));
    for (int x=ar; x<=br; x++) {
        for (int y=ac; y<=bc; y++) {
            if (board[x][y]) continue;
            int node = (x-ar) * (bc-ac+1) + y-ac;
            for (int k=0; k<4; k++) {
                int nx = x + dx[k];
                int ny = y + dy[k];
                if (nx < ar || nx > br || ny < ac || ny > bc) continue;
                if (board[nx][ny]) continue;
                int nnode = (nx-ar) * (bc-ac+1) + ny-ac;
                dsu.Union(node, nnode);
            }
        }
    }
    int ans = 0;
    for (int x=ar; x<=br; x++) {
        for (int y=ac; y<=bc; y++) {
            if (board[x][y]) continue;
            int node = (x-ar) * (bc-ac+1) + y-ac;
            if (dsu.Find(node) == node) ans ++;
        }
    }
    return ans;
}
/*
static int R, C, M, Q;
static int sr, sc;
static char S[100000 + 5];

int main() {
    scanf("%d %d %d %d", &R, &C, &M, &Q);
    scanf("%d %d", &sr, &sc);
    if (M > 0) {
        scanf(" %s ", S);
    }

    init(R, C, sr, sc, M, S);

    int query;
    for (query = 0; query < Q; query++) {
        int ar, ac, br, bc;
        scanf("%d %d %d %d", &ar, &ac, &br, &bc);
        printf("%d\n", colour(ar, ac, br, bc));
    }

    return 0;
}
*/


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 8 ms 452 KB Output is correct
3 Correct 14 ms 488 KB Output is correct
4 Correct 11 ms 496 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 9 ms 516 KB Output is correct
12 Correct 8 ms 348 KB Output is correct
13 Correct 10 ms 448 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 2 ms 2908 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 8 ms 452 KB Output is correct
3 Correct 14 ms 488 KB Output is correct
4 Correct 11 ms 496 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 9 ms 516 KB Output is correct
12 Correct 8 ms 348 KB Output is correct
13 Correct 10 ms 448 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Runtime error 1 ms 860 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 8 ms 452 KB Output is correct
3 Correct 14 ms 488 KB Output is correct
4 Correct 11 ms 496 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 9 ms 516 KB Output is correct
12 Correct 8 ms 348 KB Output is correct
13 Correct 10 ms 448 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Runtime error 1 ms 860 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -