제출 #814646

#제출 시각아이디문제언어결과실행 시간메모리
814646tranxuanbachCell Automaton (JOI23_cell)C++17
16 / 100
521 ms66900 KiB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (auto i = (l); i < (r); i++)
#define ForE(i, l, r) for (auto i = (l); i <= (r); i++)
#define FordE(i, l, r) for (auto i = (l); i >= (r); i--)
#define Fora(v, a) for (auto v: (a))
#define bend(a) (a).begin(), (a).end()
#define isz(a) ((signed)(a).size())

using ll = long long;
using ld = long double;
using pii = pair <int, int>;
using vi = vector <int>;
using vpii = vector <pii>;
using vvi = vector <vi>;

const int N = 1e5 + 5, Q = 5e5 + 5;

struct point{
    int x, y;
};

int n, q;
point a[N];
int b[Q];

namespace subtask12{
    bool check(){
        ForE(i, 1, n){
            if (not (abs(a[i].x) <= 1000 and abs(a[i].y) <= 1000)){
                return false;
            }
        }
        ForE(i, 1, q){
            if (not (b[i] <= 1000)){
                return false;
            }
        }
        return true;
    }

    const int N = 4e3 + 5, offset = 2e3;

    int dist[N][N];
    int ans[N];

    vpii dir = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};

    void solve(){
        For(x, 0, N){
            For(y, 0, N){
                dist[x][y] = -1;
            }
        }
        queue <pii> qu;
        ForE(i, 1, n){
            a[i].x += offset; a[i].y += offset;
            dist[a[i].x][a[i].y] = 0;
            qu.emplace(a[i].x, a[i].y);
        }
        while (not qu.empty()){
            auto [x, y] = qu.front(); qu.pop();
            ans[dist[x][y]]++;
            if (dist[x][y] == N - 1){
                break;
            }
            for (auto [dx, dy]: dir){
                int tx = x + dx, ty = y + dy;
                if (0 <= tx and tx < N and 0 <= ty and ty < N and dist[tx][ty] == -1){
                    dist[tx][ty] = dist[x][y] + 1;
                    qu.emplace(tx, ty);
                }
            }
        }
        ForE(i, 1, q){
            cout << ans[b[i]] << "\n";
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("KEK.inp", "r", stdin);
    // freopen("KEK.out", "w", stdout);
    cin >> n >> q;
    ForE(i, 1, n){
        cin >> a[i].x >> a[i].y;
    }
    ForE(i, 1, q){
        cin >> b[i];
    }

    if (subtask12::check()){
        subtask12::solve();
        return 0;
    }
}

/*
==================================================+
INPUT                                             |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
OUTPUT                                            |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
*/
#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...