Submission #33757


Source Code Expand

Copy
#include <cstdio>
#include <set>

using namespace std;

int h, w, c = 1;
char s[1000][1001];
int a[1000][1000];
int f[1000][1000];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int dx2[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy2[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
set <int> se;

bool in(int x, int y)
{
    if (x >= 0 && x < h && y >= 0 && y < w) {
        return true;
    } else {
        return false;
    }
}

void dfs(int x, int y)
{
    int i;
    
    a[x][y] = c;
    
    for (i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        
        if (in(nx, ny) && s[nx][ny] == '.' && a[nx][ny] == 0) dfs(nx, ny);
    }
}

void dfs2(int x, int y)
{
    int i;
    
    f[x][y] = 1;
    
    for (i = 0; i < 8; i++) {
        int nx = x + dx2[i];
        int ny = y + dy2[i];
        
        if (in(nx, ny)) {
            if (s[nx][ny] == '.') {
                se.insert(a[nx][ny]);
            } else if (f[nx][ny] == 0) {
                dfs2(nx, ny);
            }
        }
    }
}

void dfs3(int x, int y)
{
    int i;
    
    s[x][y] = '.';
    
    for (i = 0; i < 8; i++) {
        int nx = x + dx2[i];
        int ny = y + dy2[i];
        
        if (in(nx, ny) && s[nx][ny] == 'o') dfs3(nx, ny);
    }
}

int main()
{
    int i, j;
    int b[3] = {0};
    
    scanf("%d %d", &h, &w);
    
    for (i = 0; i < h; i++) scanf("%s", s[i]);
    
    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            if (s[i][j] == '.' && a[i][j] == 0) {
                dfs(i, j);
                
                c++;
            }
        }
    }
    
    c = 1;
    
    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            if (s[i][j] == 'o') {
                se.clear();
                
                dfs2(i, j);
                
                if (se.size() == 2) {
                    b[0]++;
                } else if (se.size() == 3) {
                    b[1]++;
                } else {
                    b[2]++;
                }
                
                dfs3(i, j);
            }
        }
    }
    
    printf("%d %d %d\n", b[0], b[1], b[2]);
    
    return 0;
}

Submission Info

Submission Time
Task D - アルファベット探し
User kawatea
Language C++ (G++ 4.6.4)
Score 0
Code Size 2283 Byte
Status RE
Exec Time 309 ms
Memory 19060 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:78:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:80:46: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 54
RE × 4
Set Name Test Cases
All 00_min.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt, 01_rndsmall_00.txt, 01_rndsmall_01.txt, 01_rndsmall_02.txt, 01_rndsmall_03.txt, 01_rndsmall_04.txt, 01_rndsmall_05.txt, 01_rndsmall_06.txt, 01_rndsmall_07.txt, 01_rndsmall_08.txt, 01_rndsmall_09.txt, 01_rndsmall_10.txt, 01_rndsmall_11.txt, 01_rndsmall_12.txt, 01_rndsmall_13.txt, 01_rndsmall_14.txt, 01_rndsmall_15.txt, 01_rndsmall_16.txt, 01_rndsmall_17.txt, 01_rndsmall_18.txt, 01_rndsmall_19.txt, 02_rndmax_00.txt, 02_rndmax_01.txt, 02_rndmax_02.txt, 02_rndmax_03.txt, 02_rndmax_04.txt, 02_rndmax_05.txt, 02_rndmax_06.txt, 02_rndmax_07.txt, 02_rndmax_08.txt, 02_rndmax_09.txt, 02_rndmax_10.txt, 02_rndmax_11.txt, 02_rndmax_12.txt, 02_rndmax_13.txt, 02_rndmax_14.txt, 02_rndmax_15.txt, 02_rndmax_16.txt, 02_rndmax_17.txt, 02_rndmax_18.txt, 02_rndmax_19.txt, 03_rnd_00.txt, 03_rnd_01.txt, 03_rnd_02.txt, 03_rnd_03.txt, 03_rnd_04.txt, 03_rnd_05.txt, 03_rnd_06.txt, 03_rnd_07.txt, 03_rnd_08.txt, 03_rnd_09.txt, 04_empty_00.txt, 05_maxret_00.txt
Case Name Status Exec Time Memory
00_min.txt AC 21 ms 816 KB
00_sample_01.txt AC 21 ms 768 KB
00_sample_02.txt AC 22 ms 764 KB
00_sample_03.txt AC 22 ms 912 KB
00_sample_04.txt AC 20 ms 736 KB
00_sample_05.txt AC 24 ms 1036 KB
01_rndsmall_00.txt AC 24 ms 1652 KB
01_rndsmall_01.txt AC 24 ms 1656 KB
01_rndsmall_02.txt AC 25 ms 1676 KB
01_rndsmall_03.txt AC 24 ms 1648 KB
01_rndsmall_04.txt AC 24 ms 1676 KB
01_rndsmall_05.txt AC 24 ms 1656 KB
01_rndsmall_06.txt AC 24 ms 1656 KB
01_rndsmall_07.txt AC 24 ms 1688 KB
01_rndsmall_08.txt AC 24 ms 1660 KB
01_rndsmall_09.txt AC 25 ms 1660 KB
01_rndsmall_10.txt AC 24 ms 1684 KB
01_rndsmall_11.txt AC 24 ms 1660 KB
01_rndsmall_12.txt AC 25 ms 1720 KB
01_rndsmall_13.txt AC 24 ms 1688 KB
01_rndsmall_14.txt AC 24 ms 1660 KB
01_rndsmall_15.txt AC 24 ms 1656 KB
01_rndsmall_16.txt AC 24 ms 1652 KB
01_rndsmall_17.txt AC 25 ms 1656 KB
01_rndsmall_18.txt AC 24 ms 1668 KB
01_rndsmall_19.txt AC 24 ms 1632 KB
02_rndmax_00.txt AC 97 ms 17020 KB
02_rndmax_01.txt AC 104 ms 14072 KB
02_rndmax_02.txt AC 125 ms 14980 KB
02_rndmax_03.txt AC 107 ms 15364 KB
02_rndmax_04.txt AC 120 ms 12464 KB
02_rndmax_05.txt AC 107 ms 15604 KB
02_rndmax_06.txt RE 309 ms 14584 KB
02_rndmax_07.txt RE 282 ms 13952 KB
02_rndmax_08.txt AC 102 ms 14080 KB
02_rndmax_09.txt AC 99 ms 17524 KB
02_rndmax_10.txt AC 101 ms 17264 KB
02_rndmax_11.txt AC 100 ms 14852 KB
02_rndmax_12.txt AC 102 ms 16260 KB
02_rndmax_13.txt AC 110 ms 18556 KB
02_rndmax_14.txt RE 281 ms 15216 KB
02_rndmax_15.txt AC 111 ms 13564 KB
02_rndmax_16.txt AC 101 ms 14456 KB
02_rndmax_17.txt AC 101 ms 18172 KB
02_rndmax_18.txt AC 102 ms 19060 KB
02_rndmax_19.txt AC 105 ms 15096 KB
03_rnd_00.txt AC 24 ms 1144 KB
03_rnd_01.txt AC 52 ms 9224 KB
03_rnd_02.txt AC 44 ms 4724 KB
03_rnd_03.txt AC 47 ms 8184 KB
03_rnd_04.txt AC 46 ms 5360 KB
03_rnd_05.txt AC 28 ms 2964 KB
03_rnd_06.txt AC 65 ms 7680 KB
03_rnd_07.txt AC 34 ms 3716 KB
03_rnd_08.txt AC 77 ms 15608 KB
03_rnd_09.txt AC 63 ms 8312 KB
04_empty_00.txt RE 282 ms 12928 KB
05_maxret_00.txt AC 155 ms 18036 KB