# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
813359 | arnold518 | Cell Automaton (JOI23_cell) | C++17 | 225 ms | 43952 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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[4010][4010];
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+2000][A[i].second+2000]=1;
Q.push({A[i].first+2000, A[i].second+2000});
}
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |