답안 #28345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28345 2017-07-16T04:53:16 Z 三( ε:)(#1146, xdoju, veckal, unused) Oriental P.A.D.A.K (FXCUP2_padak) C++14
0 / 1
0 ms 5932 KB
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> dist;
int cnt[1000005];

constexpr int dr[4][2] =
{
    1,0,
    0,1,
    -1,0,
    0,-1
};

int main()
{
    int n, m, k, b, z; 
    scanf("%d%d%d%d%d",&n,&m,&k,&b,&z);

    dist.resize(n, vector<int>(m));

    queue<pair<int, int>> que;

    for (int i = 0; i < k; i++)
    {
        int x, y;
        scanf("%d%d",&x,&y);
        x--; y--;
        if (dist[x][y] == 0)
        {
            dist[x][y] = 1;
            que.emplace(x, y);
        }
    }

    while (que.empty() == false)
    {
        int x, y;
        tie(x, y) = que.front();
        que.pop();

        for (int d = 0; d < 4; d++)
        {
            int nx = x + dr[d][0];
            int ny = y + dr[d][1];

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

            dist[nx][ny] = dist[x][y] + 1;
            que.emplace(nx, ny);
        }
    }

    vector<int> vt;
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (dist[i][j] > 1) vt.push_back(dist[i][j] - 1);

    sort(vt.begin(), vt.end());

    int ans1 = 0;

    for (int i = 1, p = (int)vt.size() - 1; p >= 0; i++)
    {
        bool yes = false;
        for (int j = 0; j < k && p >= 0 && vt[p] >= i; j++, ans1++, p--, yes = true)
            ;

        if (yes == false) break;
    }

    printf("%d ", ans1);

    int ans2 = 0;

    for (int i = 1, p = 0; p < vt.size(); i++)
    {
        while (p < vt.size() && vt[p] < i) ++p;
        for (int j = 0; j < k && p < vt.size(); j++, ans2++, p++)
            ;
    }

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

Compilation message

padak.cpp: In function 'int main()':
padak.cpp:74:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1, p = 0; p < vt.size(); i++)
                              ^
padak.cpp:76:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (p < vt.size() && vt[p] < i) ++p;
                  ^
padak.cpp:77:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < k && p < vt.size(); j++, ans2++, p++)
                                    ^
padak.cpp:18:39: 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,&b,&z);
                                       ^
padak.cpp:27:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&x,&y);
                            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5932 KB Output is correct
2 Incorrect 0 ms 5932 KB Output isn't correct
3 Halted 0 ms 0 KB -