답안 #1054074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054074 2024-08-12T05:50:05 Z ㅇ(#11107) 무지개나라 (APIO17_rainbow) C++14
100 / 100
464 ms 170064 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
using pii=array<int,2>;
const int N=200005,M=5e7;
int r,c;
pii X,Y;
set<pii> S[4];
struct node{
	int l=0,r=0,v=0;
}T[M]; int NC;
int root[4][N];
void upd(int n1,int n2,int l,int r,int x){
	T[n2]=T[n1];
	T[n2].v++;
	if(l==r) return;
	int m=(l+r)>>1;
	if(x<=m){
		T[n2].l=++NC;
		upd(T[n1].l,T[n2].l,l,m,x);
	} else{
		T[n2].r=++NC;
		upd(T[n1].r,T[n2].r,m+1,r,x);
	}
}
int qry(int n1,int n2,int l,int r,int s,int e){
	if(r<s||e<l||!n2) return 0;
	if(s<=l&&r<=e) return T[n2].v-T[n1].v;
	int m=(l+r)>>1;
	return qry(T[n1].l,T[n2].l,l,m,s,e)+qry(T[n1].r,T[n2].r,m+1,r,s,e);
}
void init(int R, int C, int sr, int sc, int M, char *s) {
	r=R; c=C;
	X[0]=X[1]=sr;
	Y[0]=Y[1]=sc;
	S[0].insert({sr,sc});
	S[0].insert({sr+1,sc});
	S[0].insert({sr,sc+1});
	S[0].insert({sr+1,sc+1});
	S[1].insert({sr,sc});
	S[1].insert({sr+1,sc});
	S[2].insert({sr,sc});
	S[2].insert({sr,sc+1});
	S[3].insert({sr,sc});
	for(int i=0;i<M;i++){
		if(s[i]=='N') sr--;
		if(s[i]=='W') sc--;
		if(s[i]=='S') sr++;
		if(s[i]=='E') sc++;
		X[0]=min(X[0],sr);
		X[1]=max(X[1],sr);
		Y[0]=min(Y[0],sc);
		Y[1]=max(Y[1],sc);
		S[0].insert({sr,sc});
		S[0].insert({sr+1,sc});
		S[0].insert({sr,sc+1});
		S[0].insert({sr+1,sc+1});
		S[1].insert({sr,sc});
		S[1].insert({sr+1,sc});
		S[2].insert({sr,sc});
		S[2].insert({sr,sc+1});
		S[3].insert({sr,sc});
	}
	for(int t=0;t<4;t++){
		int prv=0;
		for(auto [x,y]: S[t]){
			while(prv!=x){
				prv++;
				root[t][prv]=root[t][prv-1];
			}
			int nroot=++NC;
			upd(root[t][x],nroot,1,c+1,y);
			root[t][x]=nroot;
		}
		for(int i=prv+1;i<=r+1;i++) root[t][i]=root[t][i-1];
	}
}
int colour(int ar, int ac, int br, int bc) {
	int V=0,E=0,F=0,C=0;
	if(ar+1<=br&&ac+1<=bc) V=qry(root[0][ar],root[0][br],1,c+1,ac+1,bc);
	V+=2*(br-ar+1+bc-ac+1);
	if(ar+1<=br) E+=qry(root[1][ar],root[1][br],1,c+1,ac,bc);
	if(ac+1<=bc) E+=qry(root[2][ar-1],root[2][br],1,c+1,ac+1,bc);
	E+=2*(br-ar+1+bc-ac+1);
	F=qry(root[3][ar-1],root[3][br],1,c+1,ac,bc)+1;
	if(ar<X[0]&&X[1]<br&&ac<Y[0]&&Y[1]<bc) C=1;
	C++;
	// V - E + (F' + ans) = C + 1
	return -V+E-F+C+1;
}

Compilation message

rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:71:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   71 |   for(auto [x,y]: S[t]){
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 360 KB Output is correct
2 Correct 2 ms 1112 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 828 KB Output is correct
13 Correct 2 ms 1432 KB Output is correct
14 Correct 4 ms 1628 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 173 ms 96900 KB Output is correct
4 Correct 280 ms 161872 KB Output is correct
5 Correct 298 ms 161548 KB Output is correct
6 Correct 263 ms 124252 KB Output is correct
7 Correct 287 ms 121940 KB Output is correct
8 Correct 48 ms 1032 KB Output is correct
9 Correct 285 ms 161676 KB Output is correct
10 Correct 290 ms 161616 KB Output is correct
11 Correct 256 ms 124244 KB Output is correct
12 Correct 218 ms 151680 KB Output is correct
13 Correct 227 ms 161688 KB Output is correct
14 Correct 233 ms 161460 KB Output is correct
15 Correct 221 ms 124244 KB Output is correct
16 Correct 197 ms 114516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 216 ms 164164 KB Output is correct
3 Correct 164 ms 164176 KB Output is correct
4 Correct 175 ms 164180 KB Output is correct
5 Correct 134 ms 124500 KB Output is correct
6 Correct 67 ms 34604 KB Output is correct
7 Correct 105 ms 64592 KB Output is correct
8 Correct 187 ms 129308 KB Output is correct
9 Correct 162 ms 112208 KB Output is correct
10 Correct 54 ms 26196 KB Output is correct
11 Correct 123 ms 73556 KB Output is correct
12 Correct 210 ms 164368 KB Output is correct
13 Correct 158 ms 164180 KB Output is correct
14 Correct 194 ms 164340 KB Output is correct
15 Correct 137 ms 124500 KB Output is correct
16 Correct 67 ms 29608 KB Output is correct
17 Correct 103 ms 64596 KB Output is correct
18 Correct 183 ms 164364 KB Output is correct
19 Correct 179 ms 166560 KB Output is correct
20 Correct 181 ms 166228 KB Output is correct
21 Correct 169 ms 129376 KB Output is correct
22 Correct 165 ms 112144 KB Output is correct
23 Correct 50 ms 26196 KB Output is correct
24 Correct 125 ms 73464 KB Output is correct
25 Correct 207 ms 164320 KB Output is correct
26 Correct 164 ms 164180 KB Output is correct
27 Correct 197 ms 164180 KB Output is correct
28 Correct 135 ms 124288 KB Output is correct
29 Correct 73 ms 29524 KB Output is correct
30 Correct 125 ms 64444 KB Output is correct
31 Correct 173 ms 164204 KB Output is correct
32 Correct 180 ms 166272 KB Output is correct
33 Correct 194 ms 166228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 360 KB Output is correct
2 Correct 2 ms 1112 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 828 KB Output is correct
13 Correct 2 ms 1432 KB Output is correct
14 Correct 4 ms 1628 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 269 ms 58256 KB Output is correct
19 Correct 82 ms 7708 KB Output is correct
20 Correct 68 ms 3988 KB Output is correct
21 Correct 74 ms 4568 KB Output is correct
22 Correct 79 ms 4980 KB Output is correct
23 Correct 87 ms 7592 KB Output is correct
24 Correct 75 ms 4324 KB Output is correct
25 Correct 70 ms 4808 KB Output is correct
26 Correct 73 ms 5064 KB Output is correct
27 Correct 177 ms 47428 KB Output is correct
28 Correct 121 ms 25116 KB Output is correct
29 Correct 158 ms 44212 KB Output is correct
30 Correct 318 ms 111184 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 226 ms 47432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 360 KB Output is correct
2 Correct 2 ms 1112 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 828 KB Output is correct
13 Correct 2 ms 1432 KB Output is correct
14 Correct 4 ms 1628 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 269 ms 58256 KB Output is correct
19 Correct 82 ms 7708 KB Output is correct
20 Correct 68 ms 3988 KB Output is correct
21 Correct 74 ms 4568 KB Output is correct
22 Correct 79 ms 4980 KB Output is correct
23 Correct 87 ms 7592 KB Output is correct
24 Correct 75 ms 4324 KB Output is correct
25 Correct 70 ms 4808 KB Output is correct
26 Correct 73 ms 5064 KB Output is correct
27 Correct 177 ms 47428 KB Output is correct
28 Correct 121 ms 25116 KB Output is correct
29 Correct 158 ms 44212 KB Output is correct
30 Correct 318 ms 111184 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 226 ms 47432 KB Output is correct
33 Correct 216 ms 164164 KB Output is correct
34 Correct 164 ms 164176 KB Output is correct
35 Correct 175 ms 164180 KB Output is correct
36 Correct 134 ms 124500 KB Output is correct
37 Correct 67 ms 34604 KB Output is correct
38 Correct 105 ms 64592 KB Output is correct
39 Correct 187 ms 129308 KB Output is correct
40 Correct 162 ms 112208 KB Output is correct
41 Correct 54 ms 26196 KB Output is correct
42 Correct 123 ms 73556 KB Output is correct
43 Correct 210 ms 164368 KB Output is correct
44 Correct 158 ms 164180 KB Output is correct
45 Correct 194 ms 164340 KB Output is correct
46 Correct 137 ms 124500 KB Output is correct
47 Correct 67 ms 29608 KB Output is correct
48 Correct 103 ms 64596 KB Output is correct
49 Correct 183 ms 164364 KB Output is correct
50 Correct 179 ms 166560 KB Output is correct
51 Correct 181 ms 166228 KB Output is correct
52 Correct 169 ms 129376 KB Output is correct
53 Correct 165 ms 112144 KB Output is correct
54 Correct 50 ms 26196 KB Output is correct
55 Correct 125 ms 73464 KB Output is correct
56 Correct 207 ms 164320 KB Output is correct
57 Correct 164 ms 164180 KB Output is correct
58 Correct 197 ms 164180 KB Output is correct
59 Correct 135 ms 124288 KB Output is correct
60 Correct 73 ms 29524 KB Output is correct
61 Correct 125 ms 64444 KB Output is correct
62 Correct 173 ms 164204 KB Output is correct
63 Correct 180 ms 166272 KB Output is correct
64 Correct 194 ms 166228 KB Output is correct
65 Correct 173 ms 96900 KB Output is correct
66 Correct 280 ms 161872 KB Output is correct
67 Correct 298 ms 161548 KB Output is correct
68 Correct 263 ms 124252 KB Output is correct
69 Correct 287 ms 121940 KB Output is correct
70 Correct 48 ms 1032 KB Output is correct
71 Correct 285 ms 161676 KB Output is correct
72 Correct 290 ms 161616 KB Output is correct
73 Correct 256 ms 124244 KB Output is correct
74 Correct 218 ms 151680 KB Output is correct
75 Correct 227 ms 161688 KB Output is correct
76 Correct 233 ms 161460 KB Output is correct
77 Correct 221 ms 124244 KB Output is correct
78 Correct 197 ms 114516 KB Output is correct
79 Correct 464 ms 132900 KB Output is correct
80 Correct 373 ms 115652 KB Output is correct
81 Correct 143 ms 29520 KB Output is correct
82 Correct 249 ms 76892 KB Output is correct
83 Correct 322 ms 167760 KB Output is correct
84 Correct 232 ms 167816 KB Output is correct
85 Correct 238 ms 167908 KB Output is correct
86 Correct 234 ms 127828 KB Output is correct
87 Correct 113 ms 32912 KB Output is correct
88 Correct 143 ms 68176 KB Output is correct
89 Correct 216 ms 167764 KB Output is correct
90 Correct 294 ms 170064 KB Output is correct
91 Correct 277 ms 169808 KB Output is correct