Submission #813354

#TimeUsernameProblemLanguageResultExecution timeMemory
813354arnold518Cell Automaton (JOI23_cell)C++17
4 / 100
146 ms51020 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;
const int MAXM = 5e5;

int N, M;
pii A[MAXN+10];
int B[MAXM+10];

int P[3010][3010];

const int dy[]={-1, 1, 0, 0};
const int dx[]={0, 0, -1, 1};

int ans[1010];

int main()
{
    scanf("%d%d", &N, &M);
    for(int i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second);
    for(int i=1; i<=M; i++) scanf("%d", &B[i]);

    queue<pii> Q;
    for(int i=1; i<=N; i++)
    {
        P[A[i].first+1000][A[i].second+1000]=1;
        Q.push({A[i].first+1000, A[i].second+1000});
    }

    while(!Q.empty())
    {
        pii now=Q.front(); Q.pop();
        ans[P[now.first][now.second]-1]++;
        if(P[now.first][now.second]>B[M]+1) continue;
        for(int i=0; i<4; i++)
        {
            int ny=now.first+dy[i], nx=now.second+dx[i];
            if(P[ny][nx]) continue;
            P[ny][nx]=P[now.first][now.second]+1;
            Q.push({ny, nx});
        }
    }

    for(int i=1; i<=M; i++) printf("%d\n", ans[B[i]]);
}

Compilation message (stderr)

cell.cpp: In function 'int main()':
cell.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d%d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~
cell.cpp:25:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     for(int i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second);
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cell.cpp:26:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     for(int i=1; i<=M; i++) scanf("%d", &B[i]);
      |                             ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...