Submission #28449

# Submission time Handle Problem Language Result Execution time Memory
28449 2017-07-16T06:02:27 Z ㅁㄴㅇㄹ호(#1227, gs13105) Oriental P.A.D.A.K (FXCUP2_padak) C++14
1 / 1
399 ms 13816 KB
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <tuple>

using namespace std;

int qx[1000000];
int qy[1000000];

bool chk[1000000];

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

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

    int n, m, k, z, x, y, nx, ny, s, c, i, j;
    scanf("%d%d%d%*d%d", &n, &m, &k, &z);

    int as = 0;
    int qs = 0, qg = 0;
    const int siz = 1000000;

    for(i = 0; i<k; i++)
    {
        scanf("%d%d", &x, &y);
        x--;
        y--;
        if(chk[x*m + y])
            continue;
        chk[x*m + y] = 1;
        qx[qg%siz] = x;
        qy[qg%siz] = y;
        qg++;
    }

    for(c = 1; qs < qg; c++)
    {
        s = qg - qs;
        for(i = 0; i<s; i++)
        {
            x = qx[qs%siz];
            y = qy[qs%siz];
            qs++;

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

                if(nx<0 || nx>=n || ny<0 || ny>=m || chk[nx*m + ny])
                    continue;

                chk[nx*m + ny] = 1;
                arr[as++] = c;

                qx[qg%siz] = nx;
                qy[qg%siz] = ny;
                qg++;
            }
        }
    }

    sort(arr, arr + as);

    int r1 = 0, r2 = 0;
    int p = 0;
    for(i = 1;; i++)
    {
        while(p != as && arr[p] < i)
            p++;

        if(p == as)
            break;

        r1 += min(z, as - p);
        p += min(z, as - p);
    }

    p = as - 1;
    for(i = 1;; i++)
    {
        
        for(j = 0; j<z; j++)
        {
            if(p == -1 || arr[p] < i)
                break;

            r2++;
            p--;
        }

        if(p == -1 || arr[p] < i)
            break;
    }

    printf("%d %d\n", r2, r1);
    return 0;
}

Compilation message

padak.cpp: In function 'int main()':
padak.cpp:27:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%*d%d", &n, &m, &k, &z);
                                         ^
padak.cpp:35:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
                              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13816 KB Output is correct
2 Correct 0 ms 13816 KB Output is correct
3 Correct 39 ms 13816 KB Output is correct
4 Correct 33 ms 13816 KB Output is correct
5 Correct 43 ms 13816 KB Output is correct
6 Correct 36 ms 13816 KB Output is correct
7 Correct 46 ms 13816 KB Output is correct
8 Correct 43 ms 13816 KB Output is correct
9 Correct 36 ms 13816 KB Output is correct
10 Correct 43 ms 13816 KB Output is correct
11 Correct 39 ms 13816 KB Output is correct
12 Correct 63 ms 13816 KB Output is correct
13 Correct 26 ms 13816 KB Output is correct
14 Correct 43 ms 13816 KB Output is correct
15 Correct 36 ms 13816 KB Output is correct
16 Correct 29 ms 13816 KB Output is correct
17 Correct 59 ms 13816 KB Output is correct
18 Correct 43 ms 13816 KB Output is correct
19 Correct 43 ms 13816 KB Output is correct
20 Correct 43 ms 13816 KB Output is correct
21 Correct 46 ms 13816 KB Output is correct
22 Correct 36 ms 13816 KB Output is correct
23 Correct 46 ms 13816 KB Output is correct
24 Correct 316 ms 13816 KB Output is correct
25 Correct 399 ms 13816 KB Output is correct
26 Correct 363 ms 13816 KB Output is correct
27 Correct 309 ms 13816 KB Output is correct
28 Correct 346 ms 13816 KB Output is correct
29 Correct 319 ms 13816 KB Output is correct
30 Correct 373 ms 13816 KB Output is correct
31 Correct 33 ms 13816 KB Output is correct
32 Correct 39 ms 13816 KB Output is correct