제출 #1324355

#제출 시각아이디문제언어결과실행 시간메모리
1324355quollcucumber`Cell Automaton (JOI23_cell)C++20
16 / 100
161 ms25412 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
// bool seen[10000000];
// #define p1 ((int)(1234567891))
// bool inset(pair<int, int> a) {
//     while(a.first < 0) a.first += 30495706;
//     while(a.second < 0) a.second += 609374059;
//     return seen[((a.first * p1 + a.second) % 10000000)];
// }
// void setindex(pair<int, int> a) {
//     while(a.first < 0) a.first += 30495706;
//     while(a.second < 0) a.second += 609374059;
//     seen[((a.first * p1 + a.second) % 10000000)] = true;
// }
bool seen[5000][5000];
bool inset(pair<int, int> a) {
    a.first += 2500;
    a.second += 2500;
    return seen[a.first][a.second];
}
void setindex(pair<int, int> a) {
    a.first += 2500;
    a.second += 2500;
    seen[a.first][a.second] = true;
}
signed main() {
    // for(int i = -1000; i < 1000; i++) {
        // for(int j = -1000; j < 1000; j++) {
            // if(inset({i, j})) {
                // int a = 0;
            // }
            // setindex({i,j});
        // }
    // }
    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...