답안 #1117075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1117075 2024-11-22T20:00:07 Z mmk 무지개나라 (APIO17_rainbow) C++14
11 / 100
19 ms 760 KB
#include "rainbow.h"
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 60;

int grid[MAXN][MAXN], marc[MAXN][MAXN];

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

bool valid(int x, int y, pair<int,int> tleft, pair<int,int> bright)
{
    if(x <= 0 || x > 50 || x < tleft.first || x > bright.first) return false;
    if(y <= 0 || y > 50 || y < tleft.second || y > bright.second) return false;
    if(grid[x][y] == -1 || marc[x][y]) return false;
    return true;
}

void dfs(int x, int y, pair<int,int> tleft, pair<int,int> bright)
{
    // cerr << x << " " << y << "||\n";
    marc[x][y] = 1;

    for(int k = 0; k < 4; k++)
    {
        int nx = x + dx[k];
        int ny = y + dy[k];

        if(valid(nx,ny,tleft,bright))
        {
            dfs(nx,ny,tleft,bright);
        }
    }
}

int contaComp(pair<int,int> tleft, pair<int,int> bright)
{
    // int x = tleft.first, y = tleft.second;
    // int cnt = 0;

    // cerr << "\n=========\n";

    for(int i = 0; i <= 55; i++)
    {
        for(int j = 0; j <= 55; j++)
            marc[i][j] = 0;
    }

    int resp = 0;
    for(int i = tleft.first; i <= bright.first; i++)
    {
        for(int j = tleft.second; j <= bright.second; j++)
        {
            if(grid[i][j] == -1) continue;
            if(!marc[i][j])
            {
                dfs(i,j,tleft,bright);
                // cerr << "\n";
                resp++;
            }
        }
    }
    // cerr << "=========\n";

    return resp;
}

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


        y -= (S[i] == 'W');
        y += (S[i] == 'E');

        // cerr << x << " " << y << " COBRA \n";
        grid[x][y] = -1;
    }
}

int colour(int ar, int ac, int br, int bc)
{
    return contaComp({ar,ac},{br,bc});
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 6 ms 336 KB Output is correct
3 Correct 19 ms 676 KB Output is correct
4 Correct 13 ms 760 KB Output is correct
5 Correct 5 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 10 ms 592 KB Output is correct
12 Correct 9 ms 592 KB Output is correct
13 Correct 7 ms 504 KB Output is correct
14 Correct 4 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 500 KB Output is correct
3 Runtime error 2 ms 592 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Runtime error 1 ms 592 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 6 ms 336 KB Output is correct
3 Correct 19 ms 676 KB Output is correct
4 Correct 13 ms 760 KB Output is correct
5 Correct 5 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 10 ms 592 KB Output is correct
12 Correct 9 ms 592 KB Output is correct
13 Correct 7 ms 504 KB Output is correct
14 Correct 4 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 500 KB Output is correct
18 Runtime error 2 ms 592 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 6 ms 336 KB Output is correct
3 Correct 19 ms 676 KB Output is correct
4 Correct 13 ms 760 KB Output is correct
5 Correct 5 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 10 ms 592 KB Output is correct
12 Correct 9 ms 592 KB Output is correct
13 Correct 7 ms 504 KB Output is correct
14 Correct 4 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 500 KB Output is correct
18 Runtime error 2 ms 592 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -