Submission #826322

#TimeUsernameProblemLanguageResultExecution timeMemory
826322tomrukCell Automaton (JOI23_cell)C++17
16 / 100
282 ms127764 KiB
#include <bits/stdc++.h> #define N 4005 using namespace std; int d[N][N]; const int add = 2000; 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...