답안 #64189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64189 2018-08-03T13:07:22 Z jangwonyoung 무지개나라 (APIO17_rainbow) C++14
100 / 100
1974 ms 282744 KB
#include "rainbow.h"
#include<iostream>
#include<set>
using namespace std;
const int N=2e5+831,TS=2e7+2004;
typedef long long ll;
int n,m;
set<int>v[N],e1[N],e2[N],f[N];
int sum[TS],lc[TS],rc[TS];
int rv[N],re1[N],re2[N],rf[N];//Red Velvet Wendy <3
int sz;
int mass;
void put(int sr,int sc){
	for(int i=0; i<2 ;i++){
		for(int j=0; j<2 ;j++) v[sr+i].insert(sc+j);
		e1[sr].insert(sc+i);
		e2[sr+i].insert(sc);
	}
	f[sr].insert(sc);
}
int ins(int id,int pos,int l,int r){
	if(l==r){
		sz++;
		sum[sz]=sum[id]+1;
		return sz;
	}
	int mid=(l+r)/2;
	if(pos<=mid){
		ins(lc[id],pos,l,mid);
		sz++;
		lc[sz]=sz-1;
		rc[sz]=rc[id];	
	}
	else{
		ins(rc[id],pos,mid+1,r);
		sz++;
		lc[sz]=lc[id];
		rc[sz]=sz-1;	
	}
	sum[sz]=sum[lc[sz]]+sum[rc[sz]];
	return sz;
}
int qr(int id,int l,int r,int ll,int rr){
	if(r<ll || l>rr) return 0;
	if(ll<=l && r<=rr) return sum[id];
	int mid=(l+r)/2;
	return qr(lc[id],l,mid,ll,rr)+qr(rc[id],mid+1,r,ll,rr);
}
int cnt(int id1,int id2,int l,int r){
	return qr(id2,1,m+1,l,r)-qr(id1,1,m+1,l,r);
}
void init(int R, int C, int sr, int sc, int M, char *S){
	n=R,m=C;
	put(sr,sc);
	for(int i=0; i<M ;i++){
		if(S[i]=='N') sr--;
		if(S[i]=='E') sc++;
		if(S[i]=='S') sr++;
		if(S[i]=='W') sc--;
		put(sr,sc);
	}
	rv[0]=re1[0]=re2[0]=rf[0]=1;
	sz=1;
	for(int i=1; i<=n+1 ;i++){
		rv[i]=rv[i-1],re1[i]=re1[i-1],re2[i]=re2[i-1],rf[i]=rf[i-1];
		for(auto it=v[i].begin(); it!=v[i].end() ;++it) rv[i]=ins(rv[i],*it,1,m+1);
		for(auto it=e1[i].begin(); it!=e1[i].end() ;++it) re1[i]=ins(re1[i],*it,1,m+1);
		for(auto it=e2[i].begin(); it!=e2[i].end() ;++it) re2[i]=ins(re2[i],*it,1,m+1);
		for(auto it=f[i].begin(); it!=f[i].end() ;++it) rf[i]=ins(rf[i],*it,1,m+1);
	}
	mass=cnt(rf[0],rf[n],1,m+1);
}
int colour(int ar, int ac, int br, int bc){
	int v=(br-ar+bc-ac)*2+4+cnt(rv[ar],rv[br],ac+1,bc);
	int e=(br-ar+bc-ac)*2+4+cnt(re1[ar-1],re1[br],ac+1,bc)+cnt(re2[ar],re2[br],ac,bc);
	int f=cnt(rf[ar-1],rf[br],ac,bc);
	if(ar+2<=br && ac+2<=bc && cnt(rf[ar],rf[br-1],ac+1,bc-1)==mass){
		return 2+e-v-f;
	}
	return 1+e-v-f;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 38264 KB Output is correct
2 Correct 38 ms 38760 KB Output is correct
3 Correct 37 ms 38760 KB Output is correct
4 Correct 38 ms 38760 KB Output is correct
5 Correct 40 ms 39200 KB Output is correct
6 Correct 35 ms 39200 KB Output is correct
7 Correct 37 ms 39200 KB Output is correct
8 Correct 40 ms 39200 KB Output is correct
9 Correct 41 ms 39200 KB Output is correct
10 Correct 38 ms 39200 KB Output is correct
11 Correct 43 ms 39200 KB Output is correct
12 Correct 43 ms 39260 KB Output is correct
13 Correct 45 ms 39708 KB Output is correct
14 Correct 39 ms 39852 KB Output is correct
15 Correct 35 ms 39852 KB Output is correct
16 Correct 39 ms 39852 KB Output is correct
17 Correct 40 ms 39852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 39852 KB Output is correct
2 Correct 40 ms 39852 KB Output is correct
3 Correct 1002 ms 134868 KB Output is correct
4 Correct 1301 ms 199388 KB Output is correct
5 Correct 1445 ms 199388 KB Output is correct
6 Correct 1012 ms 199388 KB Output is correct
7 Correct 1420 ms 199388 KB Output is correct
8 Correct 409 ms 199388 KB Output is correct
9 Correct 1550 ms 199388 KB Output is correct
10 Correct 1621 ms 199388 KB Output is correct
11 Correct 1201 ms 199388 KB Output is correct
12 Correct 679 ms 199388 KB Output is correct
13 Correct 718 ms 199388 KB Output is correct
14 Correct 716 ms 199388 KB Output is correct
15 Correct 789 ms 199388 KB Output is correct
16 Correct 1171 ms 199388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 39852 KB Output is correct
2 Correct 604 ms 201980 KB Output is correct
3 Correct 336 ms 201980 KB Output is correct
4 Correct 299 ms 201980 KB Output is correct
5 Correct 352 ms 201980 KB Output is correct
6 Correct 144 ms 201980 KB Output is correct
7 Correct 281 ms 201980 KB Output is correct
8 Correct 539 ms 201980 KB Output is correct
9 Correct 438 ms 201980 KB Output is correct
10 Correct 130 ms 201980 KB Output is correct
11 Correct 317 ms 201980 KB Output is correct
12 Correct 606 ms 202440 KB Output is correct
13 Correct 273 ms 202440 KB Output is correct
14 Correct 302 ms 202532 KB Output is correct
15 Correct 360 ms 202532 KB Output is correct
16 Correct 133 ms 202532 KB Output is correct
17 Correct 212 ms 202532 KB Output is correct
18 Correct 535 ms 202772 KB Output is correct
19 Correct 538 ms 204068 KB Output is correct
20 Correct 394 ms 204144 KB Output is correct
21 Correct 425 ms 204144 KB Output is correct
22 Correct 415 ms 204144 KB Output is correct
23 Correct 138 ms 204144 KB Output is correct
24 Correct 317 ms 204144 KB Output is correct
25 Correct 642 ms 204144 KB Output is correct
26 Correct 293 ms 204144 KB Output is correct
27 Correct 369 ms 204144 KB Output is correct
28 Correct 383 ms 204144 KB Output is correct
29 Correct 164 ms 204144 KB Output is correct
30 Correct 265 ms 204144 KB Output is correct
31 Correct 461 ms 204260 KB Output is correct
32 Correct 406 ms 205384 KB Output is correct
33 Correct 488 ms 205384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 38264 KB Output is correct
2 Correct 38 ms 38760 KB Output is correct
3 Correct 37 ms 38760 KB Output is correct
4 Correct 38 ms 38760 KB Output is correct
5 Correct 40 ms 39200 KB Output is correct
6 Correct 35 ms 39200 KB Output is correct
7 Correct 37 ms 39200 KB Output is correct
8 Correct 40 ms 39200 KB Output is correct
9 Correct 41 ms 39200 KB Output is correct
10 Correct 38 ms 39200 KB Output is correct
11 Correct 43 ms 39200 KB Output is correct
12 Correct 43 ms 39260 KB Output is correct
13 Correct 45 ms 39708 KB Output is correct
14 Correct 39 ms 39852 KB Output is correct
15 Correct 35 ms 39852 KB Output is correct
16 Correct 39 ms 39852 KB Output is correct
17 Correct 40 ms 39852 KB Output is correct
18 Correct 1656 ms 205384 KB Output is correct
19 Correct 336 ms 205384 KB Output is correct
20 Correct 235 ms 205384 KB Output is correct
21 Correct 252 ms 205384 KB Output is correct
22 Correct 367 ms 205384 KB Output is correct
23 Correct 423 ms 205384 KB Output is correct
24 Correct 270 ms 205384 KB Output is correct
25 Correct 289 ms 205384 KB Output is correct
26 Correct 401 ms 205384 KB Output is correct
27 Correct 721 ms 205384 KB Output is correct
28 Correct 524 ms 205384 KB Output is correct
29 Correct 741 ms 205384 KB Output is correct
30 Correct 1155 ms 205384 KB Output is correct
31 Correct 41 ms 205384 KB Output is correct
32 Correct 1129 ms 205384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 38264 KB Output is correct
2 Correct 38 ms 38760 KB Output is correct
3 Correct 37 ms 38760 KB Output is correct
4 Correct 38 ms 38760 KB Output is correct
5 Correct 40 ms 39200 KB Output is correct
6 Correct 35 ms 39200 KB Output is correct
7 Correct 37 ms 39200 KB Output is correct
8 Correct 40 ms 39200 KB Output is correct
9 Correct 41 ms 39200 KB Output is correct
10 Correct 38 ms 39200 KB Output is correct
11 Correct 43 ms 39200 KB Output is correct
12 Correct 43 ms 39260 KB Output is correct
13 Correct 45 ms 39708 KB Output is correct
14 Correct 39 ms 39852 KB Output is correct
15 Correct 35 ms 39852 KB Output is correct
16 Correct 39 ms 39852 KB Output is correct
17 Correct 40 ms 39852 KB Output is correct
18 Correct 1656 ms 205384 KB Output is correct
19 Correct 336 ms 205384 KB Output is correct
20 Correct 235 ms 205384 KB Output is correct
21 Correct 252 ms 205384 KB Output is correct
22 Correct 367 ms 205384 KB Output is correct
23 Correct 423 ms 205384 KB Output is correct
24 Correct 270 ms 205384 KB Output is correct
25 Correct 289 ms 205384 KB Output is correct
26 Correct 401 ms 205384 KB Output is correct
27 Correct 721 ms 205384 KB Output is correct
28 Correct 524 ms 205384 KB Output is correct
29 Correct 741 ms 205384 KB Output is correct
30 Correct 1155 ms 205384 KB Output is correct
31 Correct 41 ms 205384 KB Output is correct
32 Correct 1129 ms 205384 KB Output is correct
33 Correct 604 ms 201980 KB Output is correct
34 Correct 336 ms 201980 KB Output is correct
35 Correct 299 ms 201980 KB Output is correct
36 Correct 352 ms 201980 KB Output is correct
37 Correct 144 ms 201980 KB Output is correct
38 Correct 281 ms 201980 KB Output is correct
39 Correct 539 ms 201980 KB Output is correct
40 Correct 438 ms 201980 KB Output is correct
41 Correct 130 ms 201980 KB Output is correct
42 Correct 317 ms 201980 KB Output is correct
43 Correct 606 ms 202440 KB Output is correct
44 Correct 273 ms 202440 KB Output is correct
45 Correct 302 ms 202532 KB Output is correct
46 Correct 360 ms 202532 KB Output is correct
47 Correct 133 ms 202532 KB Output is correct
48 Correct 212 ms 202532 KB Output is correct
49 Correct 535 ms 202772 KB Output is correct
50 Correct 538 ms 204068 KB Output is correct
51 Correct 394 ms 204144 KB Output is correct
52 Correct 425 ms 204144 KB Output is correct
53 Correct 415 ms 204144 KB Output is correct
54 Correct 138 ms 204144 KB Output is correct
55 Correct 317 ms 204144 KB Output is correct
56 Correct 642 ms 204144 KB Output is correct
57 Correct 293 ms 204144 KB Output is correct
58 Correct 369 ms 204144 KB Output is correct
59 Correct 383 ms 204144 KB Output is correct
60 Correct 164 ms 204144 KB Output is correct
61 Correct 265 ms 204144 KB Output is correct
62 Correct 461 ms 204260 KB Output is correct
63 Correct 406 ms 205384 KB Output is correct
64 Correct 488 ms 205384 KB Output is correct
65 Correct 1974 ms 211892 KB Output is correct
66 Correct 1966 ms 211892 KB Output is correct
67 Correct 786 ms 211892 KB Output is correct
68 Correct 988 ms 211892 KB Output is correct
69 Correct 1358 ms 258296 KB Output is correct
70 Correct 897 ms 261292 KB Output is correct
71 Correct 1004 ms 264300 KB Output is correct
72 Correct 823 ms 264300 KB Output is correct
73 Correct 645 ms 264300 KB Output is correct
74 Correct 758 ms 264300 KB Output is correct
75 Correct 929 ms 275960 KB Output is correct
76 Correct 1440 ms 279960 KB Output is correct
77 Correct 1062 ms 282744 KB Output is correct
78 Correct 1002 ms 134868 KB Output is correct
79 Correct 1301 ms 199388 KB Output is correct
80 Correct 1445 ms 199388 KB Output is correct
81 Correct 1012 ms 199388 KB Output is correct
82 Correct 1420 ms 199388 KB Output is correct
83 Correct 409 ms 199388 KB Output is correct
84 Correct 1550 ms 199388 KB Output is correct
85 Correct 1621 ms 199388 KB Output is correct
86 Correct 1201 ms 199388 KB Output is correct
87 Correct 679 ms 199388 KB Output is correct
88 Correct 718 ms 199388 KB Output is correct
89 Correct 716 ms 199388 KB Output is correct
90 Correct 789 ms 199388 KB Output is correct
91 Correct 1171 ms 199388 KB Output is correct