Submission #831253

#TimeUsernameProblemLanguageResultExecution timeMemory
831253pavementCell Automaton (JOI23_cell)C++17
16 / 100
578 ms127664 KiB
#include <bits/stdc++.h> using namespace std; using ii = pair<int, int>; const int D = 1000; int N, Q, X[100005], Y[100005], dist[4 * D + 5][4 * D + 5], dr[] = {-1, 0, 0, 1}, dc[] = {0, -1, 1, 0}, ans[4000005]; queue<ii> qu; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N >> Q; for (int i = 0; i <= 4 * D; i++) { for (int j = 0; j <= 4 * D; j++) { dist[i][j] = (int)1e9; } } for (int i = 1; i <= N; i++) { cin >> X[i] >> Y[i]; X[i] += 2 * D; Y[i] += 2 * D; dist[X[i]][Y[i]] = 0; qu.emplace(X[i], Y[i]); } while (!qu.empty()) { auto [r, c] = qu.front(); qu.pop(); for (int k = 0; k < 4; k++) { int nr = r + dr[k], nc = c + dc[k]; if (0 <= nr && nr <= 4 * D && 0 <= nc && nc <= 4 * D) { if (dist[nr][nc] > dist[r][c] + 1) { dist[nr][nc] = dist[r][c] + 1; qu.emplace(nr, nc); } } } } for (int i = 0; i <= 4 * D; i++) { for (int j = 0; j <= 4 * D; j++) { ans[dist[i][j]]++; } } for (int i = 1, t; i <= Q; i++) { cin >> t; cout << ans[t] << '\n'; } }
#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...