Submission #22487

# Submission time Handle Problem Language Result Execution time Memory
22487 2017-04-30T05:03:13 Z Jongwon Party(#988, gs13105) Young Zebra (KRIII5_YZ) C++14
2 / 7
26 ms 13692 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

char arr[410][410];
int chk[410][410];
int pos[410][410][2];

int res[160010];

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

char c;
int p;

int f(int x, int y, int px, int py)
{
    int r, nx, ny, npx, npy, i;

    chk[x][y] = p;
    pos[x][y][0] = px;
    pos[x][y][1] = py;

    r = 1;
    for(i = 0; i<4; i++)
    {
        nx = x + dx[i];
        ny = y + dy[i];
        npx = px;
        npy = py;

        if(nx < 0)
        {
            npx--;
            nx += n;
        }
        else if(nx >= n)
        {
            npx++;
            nx -= n;
        }

        if(ny < 0)
        {
            npy--;
            ny += m;
        }
        else if(ny >= m)
        {
            npy++;
            ny -= m;
        }

        if(arr[nx][ny] != c)
            continue;

        if(!chk[nx][ny])
        {
            int t = f(nx, ny, npx, npy);
            if(t == -1)
                return -1;

            r += t;
            continue;
        }
        
        if(pos[nx][ny][0] == npx && pos[nx][ny][1] == npy)
            continue;

        return -1;
    }

    return r;
}
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    int t, i, j;
    scanf("%d%d", &n, &m);
    for(i = 0; i<n; i++)
        scanf("%s", arr[i]);

    p = 1;
    for(i = 0; i<n; i++)
    {
        for(j = 0; j<m; j++)
        {
            if(chk[i][j])
            {
                printf("%d ", res[chk[i][j]]);
                continue;
            }

            c = arr[i][j];

            t = f(i, j, 0, 0);
            res[p++] = t;

            printf("%d ", t);
        }
        printf("\n");
    }
}

/*
5 4
0000
1101
0100
0111
0001

*/

Compilation message

YZ.cpp: In function 'int main()':
YZ.cpp:86:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
                          ^
YZ.cpp:88:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", arr[i]);
                            ^
# Verdict Execution time Memory Grader output
1 Partially correct 19 ms 5472 KB Output is partially correct
2 Partially correct 13 ms 5476 KB Output is partially correct
3 Partially correct 13 ms 4208 KB Output is partially correct
4 Partially correct 19 ms 5728 KB Output is partially correct
5 Partially correct 19 ms 4536 KB Output is partially correct
6 Partially correct 16 ms 4652 KB Output is partially correct
7 Partially correct 26 ms 6276 KB Output is partially correct
8 Partially correct 13 ms 5420 KB Output is partially correct
9 Partially correct 23 ms 6280 KB Output is partially correct
10 Correct 19 ms 6284 KB Output is correct
11 Correct 23 ms 13692 KB Output is correct
12 Correct 16 ms 13676 KB Output is correct
13 Partially correct 23 ms 4856 KB Output is partially correct
14 Partially correct 16 ms 5364 KB Output is partially correct
15 Partially correct 23 ms 4944 KB Output is partially correct
16 Partially correct 23 ms 7932 KB Output is partially correct
17 Partially correct 16 ms 8688 KB Output is partially correct
18 Partially correct 16 ms 8684 KB Output is partially correct
19 Correct 23 ms 3876 KB Output is correct
20 Partially correct 23 ms 4004 KB Output is partially correct
21 Correct 19 ms 10336 KB Output is correct
22 Correct 23 ms 6968 KB Output is correct
23 Partially correct 23 ms 3988 KB Output is partially correct
24 Partially correct 19 ms 4072 KB Output is partially correct
25 Partially correct 23 ms 7460 KB Output is partially correct
26 Correct 0 ms 3876 KB Output is correct
27 Correct 0 ms 3876 KB Output is correct
28 Correct 0 ms 3876 KB Output is correct
29 Correct 0 ms 3876 KB Output is correct
30 Correct 0 ms 3876 KB Output is correct
31 Correct 0 ms 3876 KB Output is correct
32 Correct 0 ms 3876 KB Output is correct
33 Partially correct 0 ms 3876 KB Output is partially correct
34 Correct 0 ms 3876 KB Output is correct
35 Partially correct 0 ms 3876 KB Output is partially correct
36 Partially correct 0 ms 3876 KB Output is partially correct
37 Partially correct 0 ms 3876 KB Output is partially correct
38 Correct 0 ms 3876 KB Output is correct
39 Partially correct 0 ms 3876 KB Output is partially correct
40 Partially correct 0 ms 3876 KB Output is partially correct