답안 #22800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22800 2017-04-30T07:32:47 Z 크리콘 B번 문제는 그리디로 풀려요(#918, imsifile) Donut-shaped Enclosure (KRIII5_DE) C++
7 / 7
1419 ms 78620 KB
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;

typedef long long lld;

struct intv {
	lld x, yl, yr; int sco;
	intv(lld x_=0, lld yl_=0, lld yr_=0, int sco_=0){ x=x_, yl=yl_, yr=yr_, sco=sco_; }
	bool operator< (const intv& c) const {
		if(x == c.x)return sco < c.sco;
		return x<c.x;
	}
} ba[404000];

struct iix {
	int sum, mx;
	iix(int sum_=0, int mx_=0) : sum(sum_), mx(mx_) {}
};

struct segtr {
	int l, r; int s, e;
	iix key;
	segtr(int s_=0, int e_=0) : s(s_), e(e_) {l=NULL, r=NULL;}
} itr[2500000];

int N, bcn, dap; int icn;
lld L, R;

void add(int it, int mi, int mx, int v){
	if(mi > mx)return;
	int l = itr[it].s, r = itr[it].e;
	int m = (l+r)/2;
	if(m == r && l < m)m--;
//	printf("%lld %lld %lld / %lld %lld\n", l, m, r, mi, mx);
	if(l == -1 && r == -1 && mi == 0)exit(0);
	if(l == mi && r == mx){
		itr[it].key.sum += v;
		itr[it].key.mx += v;
		return;
	}
	if(itr[it].l == 0)itr[it].l = icn++, itr[itr[it].l] = segtr(l, m);
	if(itr[it].r == 0)itr[it].r = icn++, itr[itr[it].r] = segtr(m+1, r);

	if(mx <= m) add(itr[it].l, mi, mx, v);
	else if(mi > m) add(itr[it].r, mi, mx, v);
	else{
		add(itr[it].l, mi, m, v);
		add(itr[it].r, m+1, mx, v);
	}
	itr[it].key.mx = max(itr[itr[it].l].key.mx, itr[itr[it].r].key.mx) + itr[it].key.sum;
}

lld ys[804040]; int ycn;

int main(){
	icn++;
	itr[0].s = 0, itr[0].e = 800000;
	scanf("%d %lld %lld", &N, &L, &R); L--;
	for(int i=0; i<N; i++){
		lld x, y; int s;
		scanf("%lld%lld%d", &x, &y, &s);
		ba[bcn++] = intv(x-R, y-R, y+R, s);
		ba[bcn++] = intv(x-L, y-L, y+L, -s);
		ba[bcn++] = intv(x+L+1, y-L, y+L, s);
		ba[bcn++] = intv(x+R+1, y-R, y+R, -s);
		ys[ycn++] = y-L; ys[ycn++] = y+L;
		ys[ycn++] = y-L+1; ys[ycn++] = y+L+1;
		ys[ycn++] = y-R; ys[ycn++] = y+R;
		ys[ycn++] = y-R+1; ys[ycn++] = y+R+1;
	}
	sort(ba, ba+bcn);
	sort(ys, ys+ycn); ycn = unique(ys, ys+ycn) - ys;
	for(int i=0; i<bcn; i++){
		int yl = lower_bound(ys, ys+ycn, ba[i].yl) - ys;
		int yr = lower_bound(ys, ys+ycn, ba[i].yr) - ys;
		add(0, yl, yr, ba[i].sco);
		int mx = itr[0].key.mx;
		if(dap < mx)dap = mx;
	}
	printf("%d", dap);
	return 0;
}

Compilation message

DE.cpp: In constructor 'segtr::segtr(int, int)':
DE.cpp:25:45: warning: converting to non-pointer type 'int' from NULL [-Wconversion-null]
  segtr(int s_=0, int e_=0) : s(s_), e(e_) {l=NULL, r=NULL;}
                                             ^
DE.cpp:25:53: warning: converting to non-pointer type 'int' from NULL [-Wconversion-null]
  segtr(int s_=0, int e_=0) : s(s_), e(e_) {l=NULL, r=NULL;}
                                                     ^
DE.cpp: In function 'int main()':
DE.cpp:60:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %lld %lld", &N, &L, &R); L--;
                                   ^
DE.cpp:63:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%d", &x, &y, &s);
                                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 78620 KB Output is correct
2 Correct 16 ms 78620 KB Output is correct
3 Correct 13 ms 78620 KB Output is correct
4 Correct 9 ms 78620 KB Output is correct
5 Correct 9 ms 78620 KB Output is correct
6 Correct 9 ms 78620 KB Output is correct
7 Correct 6 ms 78620 KB Output is correct
8 Correct 16 ms 78620 KB Output is correct
9 Correct 16 ms 78620 KB Output is correct
10 Correct 16 ms 78620 KB Output is correct
11 Correct 26 ms 78620 KB Output is correct
12 Correct 16 ms 78620 KB Output is correct
13 Correct 16 ms 78620 KB Output is correct
14 Correct 26 ms 78620 KB Output is correct
15 Correct 19 ms 78620 KB Output is correct
16 Correct 13 ms 78620 KB Output is correct
17 Correct 9 ms 78620 KB Output is correct
18 Correct 23 ms 78620 KB Output is correct
19 Correct 13 ms 78620 KB Output is correct
20 Correct 16 ms 78620 KB Output is correct
21 Correct 16 ms 78620 KB Output is correct
22 Correct 13 ms 78620 KB Output is correct
23 Correct 16 ms 78620 KB Output is correct
24 Correct 13 ms 78620 KB Output is correct
25 Correct 19 ms 78620 KB Output is correct
26 Correct 13 ms 78620 KB Output is correct
27 Correct 19 ms 78620 KB Output is correct
28 Correct 19 ms 78620 KB Output is correct
29 Correct 16 ms 78620 KB Output is correct
30 Correct 16 ms 78620 KB Output is correct
31 Correct 13 ms 78620 KB Output is correct
32 Correct 9 ms 78620 KB Output is correct
33 Correct 13 ms 78620 KB Output is correct
34 Correct 9 ms 78620 KB Output is correct
35 Correct 13 ms 78620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 78620 KB Output is correct
2 Correct 16 ms 78620 KB Output is correct
3 Correct 13 ms 78620 KB Output is correct
4 Correct 9 ms 78620 KB Output is correct
5 Correct 9 ms 78620 KB Output is correct
6 Correct 9 ms 78620 KB Output is correct
7 Correct 6 ms 78620 KB Output is correct
8 Correct 16 ms 78620 KB Output is correct
9 Correct 16 ms 78620 KB Output is correct
10 Correct 16 ms 78620 KB Output is correct
11 Correct 26 ms 78620 KB Output is correct
12 Correct 16 ms 78620 KB Output is correct
13 Correct 16 ms 78620 KB Output is correct
14 Correct 26 ms 78620 KB Output is correct
15 Correct 19 ms 78620 KB Output is correct
16 Correct 13 ms 78620 KB Output is correct
17 Correct 9 ms 78620 KB Output is correct
18 Correct 23 ms 78620 KB Output is correct
19 Correct 13 ms 78620 KB Output is correct
20 Correct 16 ms 78620 KB Output is correct
21 Correct 16 ms 78620 KB Output is correct
22 Correct 13 ms 78620 KB Output is correct
23 Correct 16 ms 78620 KB Output is correct
24 Correct 13 ms 78620 KB Output is correct
25 Correct 19 ms 78620 KB Output is correct
26 Correct 13 ms 78620 KB Output is correct
27 Correct 19 ms 78620 KB Output is correct
28 Correct 19 ms 78620 KB Output is correct
29 Correct 16 ms 78620 KB Output is correct
30 Correct 16 ms 78620 KB Output is correct
31 Correct 13 ms 78620 KB Output is correct
32 Correct 9 ms 78620 KB Output is correct
33 Correct 13 ms 78620 KB Output is correct
34 Correct 9 ms 78620 KB Output is correct
35 Correct 13 ms 78620 KB Output is correct
36 Correct 19 ms 78620 KB Output is correct
37 Correct 6 ms 78620 KB Output is correct
38 Correct 26 ms 78620 KB Output is correct
39 Correct 19 ms 78620 KB Output is correct
40 Correct 16 ms 78620 KB Output is correct
41 Correct 33 ms 78620 KB Output is correct
42 Correct 59 ms 78620 KB Output is correct
43 Correct 73 ms 78620 KB Output is correct
44 Correct 79 ms 78620 KB Output is correct
45 Correct 106 ms 78620 KB Output is correct
46 Correct 133 ms 78620 KB Output is correct
47 Correct 163 ms 78620 KB Output is correct
48 Correct 193 ms 78620 KB Output is correct
49 Correct 606 ms 78620 KB Output is correct
50 Correct 653 ms 78620 KB Output is correct
51 Correct 1363 ms 78620 KB Output is correct
52 Correct 1349 ms 78620 KB Output is correct
53 Correct 1343 ms 78620 KB Output is correct
54 Correct 1299 ms 78620 KB Output is correct
55 Correct 1419 ms 78620 KB Output is correct
56 Correct 1286 ms 78620 KB Output is correct
57 Correct 1296 ms 78620 KB Output is correct
58 Correct 1386 ms 78620 KB Output is correct
59 Correct 999 ms 78620 KB Output is correct
60 Correct 1343 ms 78620 KB Output is correct
61 Correct 19 ms 78620 KB Output is correct
62 Correct 99 ms 78620 KB Output is correct
63 Correct 233 ms 78620 KB Output is correct
64 Correct 556 ms 78620 KB Output is correct
65 Correct 1319 ms 78620 KB Output is correct
66 Correct 713 ms 78620 KB Output is correct
67 Correct 733 ms 78620 KB Output is correct
68 Correct 576 ms 78620 KB Output is correct
69 Correct 609 ms 78620 KB Output is correct
70 Correct 656 ms 78620 KB Output is correct
71 Correct 706 ms 78620 KB Output is correct
72 Correct 749 ms 78620 KB Output is correct
73 Correct 736 ms 78620 KB Output is correct
74 Correct 779 ms 78620 KB Output is correct
75 Correct 776 ms 78620 KB Output is correct
76 Correct 809 ms 78620 KB Output is correct
77 Correct 873 ms 78620 KB Output is correct
78 Correct 943 ms 78620 KB Output is correct
79 Correct 933 ms 78620 KB Output is correct
80 Correct 943 ms 78620 KB Output is correct