Submission #22500

# Submission time Handle Problem Language Result Execution time Memory
22500 2017-04-30T05:07:06 Z Jongwon Party(#988, gs13105) Young Zebra (KRIII5_YZ) C++14
7 / 7
29 ms 16176 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)
{
    bool u;
    int r, nx, ny, npx, npy, i;

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

    r = 1;
    u = 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)
                u = 0;
            else
                r += t;

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

        u = 0;
    }
    
    if(u)
        return r;
    return -1;
}
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");
    }
}

Compilation message

YZ.cpp: In function 'int main()':
YZ.cpp:92: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:94: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 Correct 23 ms 12788 KB Output is correct
2 Correct 16 ms 9628 KB Output is correct
3 Correct 23 ms 11780 KB Output is correct
4 Correct 13 ms 6416 KB Output is correct
5 Correct 23 ms 5452 KB Output is correct
6 Correct 19 ms 4872 KB Output is correct
7 Correct 13 ms 6920 KB Output is correct
8 Correct 16 ms 8696 KB Output is correct
9 Correct 13 ms 6920 KB Output is correct
10 Correct 16 ms 6920 KB Output is correct
11 Correct 26 ms 16176 KB Output is correct
12 Correct 19 ms 16160 KB Output is correct
13 Correct 26 ms 9268 KB Output is correct
14 Correct 19 ms 9052 KB Output is correct
15 Correct 19 ms 6528 KB Output is correct
16 Correct 19 ms 8976 KB Output is correct
17 Correct 16 ms 9924 KB Output is correct
18 Correct 26 ms 9920 KB Output is correct
19 Correct 23 ms 3876 KB Output is correct
20 Correct 19 ms 8956 KB Output is correct
21 Correct 23 ms 11980 KB Output is correct
22 Correct 29 ms 11792 KB Output is correct
23 Correct 23 ms 7484 KB Output is correct
24 Correct 26 ms 8388 KB Output is correct
25 Correct 19 ms 8392 KB Output is correct
26 Correct 0 ms 3876 KB Output is correct
27 Correct 0 ms 3876 KB Output is correct
28 Correct 0 ms 3972 KB Output is correct
29 Correct 0 ms 3972 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 Correct 0 ms 3876 KB Output is correct
34 Correct 0 ms 3876 KB Output is correct
35 Correct 0 ms 3876 KB Output is correct
36 Correct 0 ms 4312 KB Output is correct
37 Correct 0 ms 4128 KB Output is correct
38 Correct 0 ms 3876 KB Output is correct
39 Correct 0 ms 4160 KB Output is correct
40 Correct 0 ms 4236 KB Output is correct