Submission #22500

#TimeUsernameProblemLanguageResultExecution timeMemory
22500Jongwon Party (#40)Young Zebra (KRIII5_YZ)C++14
7 / 7
29 ms16176 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...