제출 #826320

#제출 시각아이디문제언어결과실행 시간메모리
826320tomrukCell Automaton (JOI23_cell)C++17
4 / 100
251 ms127816 KiB
#include <bits/stdc++.h> #define N 4005 using namespace std; int d[N][N]; const int add = 1000; int x[100005],y[100005]; int cnt[N]; void solve(){ int n,q; cin >> n >> q; memset(d,-1,sizeof d); queue<pair<int,int>> qq; for(int i =1;i<=n;i++){ cin >> x[i] >> y[i]; x[i] += add; y[i] += add; d[x[i]][y[i]] = 0; qq.push({x[i],y[i]}); } while(qq.size()){ auto tp = qq.front(); qq.pop(); auto [x,y] = tp; if(d[x][y] >= 1005) break; cnt[d[x][y]]++; for(int dx = -1;dx <=1;dx++){ for(int dy = -1;dy<=1;dy++){ if(abs(dx) + abs(dy) != 1) continue; if(d[x + dx][y + dy] == -1){ d[x + dx][y + dy] = d[x][y] + 1; qq.push({x+dx,y+dy}); } } } } while(q--){ int t; cin >> t; cout << cnt[t] << '\n'; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef Local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t=1; //cin>>t; while(t--){ solve(); } #ifdef Local cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "; #endif }
#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...