제출 #1324351

#제출 시각아이디문제언어결과실행 시간메모리
1324351quollcucumber`Cell Automaton (JOI23_cell)C++20
0 / 100
1 ms568 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
bool seen[1000000];
#define p1 ((int)(1e9 + 7))
bool inset(pair<int, int> a) {
    return seen[(a.first * p1 + a.second) % 1000000];
}
void setindex(pair<int, int> a) {
    seen[(a.first * p1 + a.second) % 1000000] = true;
}
signed main() {
    int n, q;
    cin >> n >> q;
    // int t[1005];
    // t[0] = n;
    // set<pair<int, int>> s;
    map<pair<int, int>, int> arr;
    queue<pair<int, int>> que;
    for(int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        que.push({x, y});
        setindex({x, y});
    }
    vector<int> times;
    for(int i = 0; i < q; i++) {
        int t;
        cin >> t;
        times.push_back(t);
    }
    int time = 0;
    int pos = 0;
    while(true) {
        while(time == times[pos]) {
            cout<<que.size()<<'\n';
            pos++;
        }
        time++;
        if(pos == q) {
            break;
        }
        vector<pair<int, int>> nodes;
        while(!que.empty()) {
            nodes.push_back(que.front());
            que.pop();
        }
        for(pair<int, int> i : nodes) {
            if(!inset({i.first, i.second+1})) {
                que.push({i.first, i.second+1});
                setindex({i.first, i.second+1});
            }
            if(!inset({i.first, i.second-1})) {
                que.push({i.first, i.second-1});
                setindex({i.first, i.second-1});
            }
            if(!inset({i.first+1,i.second})) {
                que.push({i.first + 1, i.second});
                setindex({i.first + 1, i.second});
            }
            if(!inset({i.first-1, i.second})) {
                que.push({i.first - 1, i.second});
                setindex({i.first - 1, i.second});
            }
        }
    }
}
#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...