답안 #826742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826742 2023-08-16T01:20:09 Z jamezzz Cell Automaton (JOI23_cell) C++17
32 / 100
452 ms 66876 KB
#include <bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define INF 2023456789
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int m=4000;

int n,k;
int num[2*m+5];
int grid[m+5][m+5];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int main(){
	sf("%d%d",&n,&k);
	vector<ii> v;
	bool st1=true,st2=true;
	for(int i=0;i<n;++i){
		int x,y;sf("%d%d",&x,&y);
		v.pb({x,y});
		st1=st1&&(max(abs(x),abs(y))<=1000);
		st2=st2&&(x==y);
	}
	if(st2){
		set<pll> s;
		ll tot=0;
		priority_queue<pll,vector<pll>,greater<pll>> pq;
		sort(all(v));
		for(int i=0;i<sz(v);++i){
			v[i]={v[i].fi+v[i].se,0};
			ll x=v[i].fi;
			if(i!=0){
				ll pv=v[i-1].fi;
				pq.push({x-pv,pv});
			}
			s.insert({x,x});
		}
		for(int i=0;i<k;++i){
			int x;sf("%d",&x);
			if(x==0){
				pf("%d\n",n);
				continue;
			}
			int bonus=0;
			while(!pq.empty()&&pq.top().fi<=2*x){
				auto[d,v]=pq.top();
				pq.pop();
				if(d==2*x)++bonus;
				auto it=--(s.upper_bound({v,INF}));
				assert(next(it)!=s.begin());
				pll pr=*it;
				assert(pr.fi<=v&&v<=pr.se);
				it=s.erase(it);
				assert(it!=s.end());
				pll pr2=*it;
				s.erase(it);
				tot-=pr.se-pr.fi;
				tot-=pr2.se-pr2.fi;
				tot+=pr2.se-pr.fi;
				s.insert({pr.fi,pr2.se});
			}
			int num=sz(s);
			pf("%lld\n",(ll)num*4*x+tot+(ll)bonus*(x-1));
		}
	}
	else if(st1){
		memset(grid,-1,sizeof grid);
		queue<ii> q;
		for(auto[x,y]:v){
			x+=m/2;y+=m/2;
			grid[x][y]=0;
			q.push({x,y});
		}
		while(!q.empty()){
			auto[x,y]=q.front();q.pop();
			for(int i=0;i<4;++i){
				int nx=x+dx[i],ny=y+dy[i];
				if(nx<0||ny<0||nx>=m||ny>=m)continue;
				if(grid[nx][ny]!=-1)continue;
				grid[nx][ny]=grid[x][y]+1;
				q.push({nx,ny});
			}
		}
		for(int i=0;i<m;++i){
			for(int j=0;j<m;++j){
				++num[grid[i][j]];
			}
		}
		for(int i=0;i<k;++i){
			int x;sf("%d",&x);
			pf("%d\n",num[x]);
		}
	}
}

Compilation message

cell.cpp: In function 'int main()':
cell.cpp:24:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  sf("%d%d",&n,&k);
      |    ^
cell.cpp:28:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   int x,y;sf("%d%d",&x,&y);
      |             ^
cell.cpp:48:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |    int x;sf("%d",&x);
      |            ^
cell.cpp:99:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |    int x;sf("%d",&x);
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 63100 KB Output is correct
2 Correct 425 ms 63124 KB Output is correct
3 Correct 410 ms 63132 KB Output is correct
4 Correct 426 ms 63136 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 428 ms 63212 KB Output is correct
9 Correct 418 ms 63252 KB Output is correct
10 Correct 414 ms 63060 KB Output is correct
11 Correct 412 ms 63324 KB Output is correct
12 Correct 416 ms 63104 KB Output is correct
13 Correct 415 ms 63144 KB Output is correct
14 Correct 410 ms 63120 KB Output is correct
15 Correct 424 ms 63128 KB Output is correct
16 Correct 416 ms 63124 KB Output is correct
17 Correct 410 ms 63092 KB Output is correct
18 Correct 411 ms 63100 KB Output is correct
19 Correct 411 ms 63132 KB Output is correct
20 Correct 421 ms 63180 KB Output is correct
21 Correct 411 ms 63092 KB Output is correct
22 Correct 440 ms 63124 KB Output is correct
23 Correct 434 ms 63140 KB Output is correct
24 Correct 422 ms 63128 KB Output is correct
25 Correct 417 ms 63124 KB Output is correct
26 Correct 426 ms 63060 KB Output is correct
27 Correct 416 ms 63060 KB Output is correct
28 Correct 439 ms 63436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 63100 KB Output is correct
2 Correct 425 ms 63124 KB Output is correct
3 Correct 410 ms 63132 KB Output is correct
4 Correct 426 ms 63136 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 428 ms 63212 KB Output is correct
9 Correct 418 ms 63252 KB Output is correct
10 Correct 414 ms 63060 KB Output is correct
11 Correct 412 ms 63324 KB Output is correct
12 Correct 416 ms 63104 KB Output is correct
13 Correct 415 ms 63144 KB Output is correct
14 Correct 410 ms 63120 KB Output is correct
15 Correct 424 ms 63128 KB Output is correct
16 Correct 416 ms 63124 KB Output is correct
17 Correct 410 ms 63092 KB Output is correct
18 Correct 411 ms 63100 KB Output is correct
19 Correct 411 ms 63132 KB Output is correct
20 Correct 421 ms 63180 KB Output is correct
21 Correct 411 ms 63092 KB Output is correct
22 Correct 440 ms 63124 KB Output is correct
23 Correct 434 ms 63140 KB Output is correct
24 Correct 422 ms 63128 KB Output is correct
25 Correct 417 ms 63124 KB Output is correct
26 Correct 426 ms 63060 KB Output is correct
27 Correct 416 ms 63060 KB Output is correct
28 Correct 439 ms 63436 KB Output is correct
29 Correct 414 ms 63060 KB Output is correct
30 Correct 424 ms 63124 KB Output is correct
31 Correct 419 ms 63180 KB Output is correct
32 Correct 439 ms 66384 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 416 ms 63212 KB Output is correct
37 Correct 409 ms 63096 KB Output is correct
38 Correct 425 ms 63388 KB Output is correct
39 Correct 419 ms 64084 KB Output is correct
40 Correct 452 ms 66876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 8900 KB Output is correct
2 Correct 48 ms 8896 KB Output is correct
3 Correct 64 ms 8900 KB Output is correct
4 Correct 89 ms 8916 KB Output is correct
5 Correct 71 ms 8892 KB Output is correct
6 Correct 81 ms 8916 KB Output is correct
7 Correct 57 ms 8896 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 94 ms 8880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 8900 KB Output is correct
2 Correct 48 ms 8896 KB Output is correct
3 Correct 64 ms 8900 KB Output is correct
4 Correct 89 ms 8916 KB Output is correct
5 Correct 71 ms 8892 KB Output is correct
6 Correct 81 ms 8916 KB Output is correct
7 Correct 57 ms 8896 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 94 ms 8880 KB Output is correct
12 Correct 197 ms 14324 KB Output is correct
13 Correct 215 ms 14392 KB Output is correct
14 Correct 196 ms 14380 KB Output is correct
15 Correct 195 ms 14388 KB Output is correct
16 Correct 91 ms 3916 KB Output is correct
17 Correct 93 ms 4024 KB Output is correct
18 Correct 103 ms 5708 KB Output is correct
19 Correct 196 ms 14344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 63100 KB Output is correct
2 Correct 425 ms 63124 KB Output is correct
3 Correct 410 ms 63132 KB Output is correct
4 Correct 426 ms 63136 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 428 ms 63212 KB Output is correct
9 Correct 418 ms 63252 KB Output is correct
10 Correct 414 ms 63060 KB Output is correct
11 Correct 412 ms 63324 KB Output is correct
12 Correct 416 ms 63104 KB Output is correct
13 Correct 415 ms 63144 KB Output is correct
14 Correct 410 ms 63120 KB Output is correct
15 Correct 424 ms 63128 KB Output is correct
16 Correct 416 ms 63124 KB Output is correct
17 Correct 410 ms 63092 KB Output is correct
18 Correct 411 ms 63100 KB Output is correct
19 Correct 411 ms 63132 KB Output is correct
20 Correct 421 ms 63180 KB Output is correct
21 Correct 411 ms 63092 KB Output is correct
22 Correct 440 ms 63124 KB Output is correct
23 Correct 434 ms 63140 KB Output is correct
24 Correct 422 ms 63128 KB Output is correct
25 Correct 417 ms 63124 KB Output is correct
26 Correct 426 ms 63060 KB Output is correct
27 Correct 416 ms 63060 KB Output is correct
28 Correct 439 ms 63436 KB Output is correct
29 Correct 414 ms 63060 KB Output is correct
30 Correct 424 ms 63124 KB Output is correct
31 Correct 419 ms 63180 KB Output is correct
32 Correct 439 ms 66384 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 416 ms 63212 KB Output is correct
37 Correct 409 ms 63096 KB Output is correct
38 Correct 425 ms 63388 KB Output is correct
39 Correct 419 ms 64084 KB Output is correct
40 Correct 452 ms 66876 KB Output is correct
41 Correct 49 ms 8900 KB Output is correct
42 Correct 48 ms 8896 KB Output is correct
43 Correct 64 ms 8900 KB Output is correct
44 Correct 89 ms 8916 KB Output is correct
45 Correct 71 ms 8892 KB Output is correct
46 Correct 81 ms 8916 KB Output is correct
47 Correct 57 ms 8896 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 94 ms 8880 KB Output is correct
52 Correct 197 ms 14324 KB Output is correct
53 Correct 215 ms 14392 KB Output is correct
54 Correct 196 ms 14380 KB Output is correct
55 Correct 195 ms 14388 KB Output is correct
56 Correct 91 ms 3916 KB Output is correct
57 Correct 93 ms 4024 KB Output is correct
58 Correct 103 ms 5708 KB Output is correct
59 Correct 196 ms 14344 KB Output is correct
60 Incorrect 0 ms 212 KB Output isn't correct
61 Halted 0 ms 0 KB -