답안 #100901

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100901 2019-03-15T04:22:37 Z cki86201 Bulldozer (JOI17_bulldozer) C++11
100 / 100
1046 ms 17016 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

pii operator-(pii a, pii b) { return pii(a.Fi - b.Fi, a.Se - b.Se); }
ll operator/(pii a, pii b) { return (ll)a.Fi * b.Se - (ll)a.Se * b.Fi; }

pii P[2020];
ll C[2020];
int N;
struct node {
	node(){}
	node(ll x) {
		sum = x;
		lv = rv = val = max(0LL, x);
	}
	ll lv, rv, sum, val;
};
node operator+(const node &a, const node &b) {
	node res;
	res.sum = a.sum + b.sum;
	res.lv = max(a.lv, a.sum + b.lv);
	res.rv = max(b.rv, b.sum + a.rv);
	res.val = max({a.val, b.val, a.rv + b.lv});
	return res;
}
node T[1<<12]; const int ADD = 1<<11;

void update(int l, ll x) {
	l += ADD; T[l] = node(x); l >>= 1;
	while(l) T[l] = T[l<<1] + T[l<<1|1], l >>= 1;
}

ll read() { return T[1].val; }

int main() {
	scanf("%d", &N);
	for(int i=1;i<=N;i++) {
		int x, y, c; scanf("%d%d%d", &x, &y, &c);
		P[i] = pii(x, y);
		C[i] = c;
	}
	vector <pii> O;
	for(int i=1;i<=N;i++) for(int j=i+1;j<=N;j++) {
		if(P[i] < P[j]) O.pb(pii(i, j));
		else O.pb(pii(j, i));
	}
	sort(all(O), [](pii a, pii b) {
		pii p1 = P[a.Se] - P[a.Fi];
		pii p2 = P[b.Se] - P[b.Fi];
		ll v = p1 / p2;
		if(v != 0) return v > 0;
		pii q1 = min(P[a.Fi], P[a.Se]);
		pii q2 = min(P[b.Fi], P[b.Se]);
		if(q1 != q2) return q1 < q2;
		q1 = max(P[a.Fi], P[a.Se]);
		q2 = max(P[b.Fi], P[b.Se]);
		return q1 < q2;
	});
	int ord[2020], ro[2020];
	for(int i=1;i<=N;i++) ord[i] = i;
	sort(ord+1, ord+1+N, [](int a, int b) {
		return P[a] < P[b];
	});
	for(int i=1;i<=N;i++) ro[ord[i]] = i;
	for(int i=1;i<=N;i++) update(i, C[ord[i]]);
	ll ans = read();
	rep(i, szz(O)) {
		pii e = O[i];
		int x = ro[e.Fi], y = ro[e.Se];
		swap(ord[x], ord[y]);
		swap(ro[e.Fi], ro[e.Se]);
		update(ro[e.Fi], C[e.Fi]);
		update(ro[e.Se], C[e.Se]);
		int ok = 0;
		if(i == szz(O)-1) ok = 1;
		else {
			pii f = O[i+1];
			pii p1 = P[e.Se] - P[e.Fi];
			pii p2 = P[f.Se] - P[f.Fi];
			if(p1 / p2 != 0) ok = 1;
		}
		if(ok) ans = max(ans, read());
	}
	printf("%lld\n", ans);
	
	return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:64:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
bulldozer.cpp:66:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y, c; scanf("%d%d%d", &x, &y, &c);
                ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 3 ms 432 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 4 ms 512 KB Output is correct
29 Correct 4 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 4 ms 508 KB Output is correct
32 Correct 4 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 3 ms 432 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 4 ms 512 KB Output is correct
29 Correct 4 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 4 ms 508 KB Output is correct
32 Correct 4 ms 512 KB Output is correct
33 Correct 863 ms 16860 KB Output is correct
34 Correct 865 ms 16944 KB Output is correct
35 Correct 911 ms 16860 KB Output is correct
36 Correct 892 ms 16856 KB Output is correct
37 Correct 865 ms 16860 KB Output is correct
38 Correct 881 ms 16872 KB Output is correct
39 Correct 912 ms 16872 KB Output is correct
40 Correct 881 ms 16984 KB Output is correct
41 Correct 874 ms 16872 KB Output is correct
42 Correct 997 ms 16864 KB Output is correct
43 Correct 887 ms 16952 KB Output is correct
44 Correct 888 ms 16888 KB Output is correct
45 Correct 867 ms 16848 KB Output is correct
46 Correct 905 ms 17016 KB Output is correct
47 Correct 895 ms 16860 KB Output is correct
48 Correct 863 ms 16864 KB Output is correct
49 Correct 861 ms 16888 KB Output is correct
50 Correct 858 ms 16868 KB Output is correct
51 Correct 857 ms 16988 KB Output is correct
52 Correct 877 ms 17000 KB Output is correct
53 Correct 910 ms 16864 KB Output is correct
54 Correct 896 ms 16860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 3 ms 432 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 4 ms 512 KB Output is correct
29 Correct 4 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 4 ms 508 KB Output is correct
32 Correct 4 ms 512 KB Output is correct
33 Correct 863 ms 16860 KB Output is correct
34 Correct 865 ms 16944 KB Output is correct
35 Correct 911 ms 16860 KB Output is correct
36 Correct 892 ms 16856 KB Output is correct
37 Correct 865 ms 16860 KB Output is correct
38 Correct 881 ms 16872 KB Output is correct
39 Correct 912 ms 16872 KB Output is correct
40 Correct 881 ms 16984 KB Output is correct
41 Correct 874 ms 16872 KB Output is correct
42 Correct 997 ms 16864 KB Output is correct
43 Correct 887 ms 16952 KB Output is correct
44 Correct 888 ms 16888 KB Output is correct
45 Correct 867 ms 16848 KB Output is correct
46 Correct 905 ms 17016 KB Output is correct
47 Correct 895 ms 16860 KB Output is correct
48 Correct 863 ms 16864 KB Output is correct
49 Correct 861 ms 16888 KB Output is correct
50 Correct 858 ms 16868 KB Output is correct
51 Correct 857 ms 16988 KB Output is correct
52 Correct 877 ms 17000 KB Output is correct
53 Correct 910 ms 16864 KB Output is correct
54 Correct 896 ms 16860 KB Output is correct
55 Correct 886 ms 16856 KB Output is correct
56 Correct 927 ms 16856 KB Output is correct
57 Correct 871 ms 17000 KB Output is correct
58 Correct 886 ms 16860 KB Output is correct
59 Correct 884 ms 16968 KB Output is correct
60 Correct 874 ms 16872 KB Output is correct
61 Correct 904 ms 16868 KB Output is correct
62 Correct 887 ms 16872 KB Output is correct
63 Correct 887 ms 16860 KB Output is correct
64 Correct 951 ms 16948 KB Output is correct
65 Correct 865 ms 16856 KB Output is correct
66 Correct 883 ms 16908 KB Output is correct
67 Correct 899 ms 16948 KB Output is correct
68 Correct 871 ms 16988 KB Output is correct
69 Correct 895 ms 16856 KB Output is correct
70 Correct 867 ms 16860 KB Output is correct
71 Correct 871 ms 16864 KB Output is correct
72 Correct 882 ms 16864 KB Output is correct
73 Correct 880 ms 16860 KB Output is correct
74 Correct 880 ms 16912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 4 ms 512 KB Output is correct
17 Correct 4 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 4 ms 512 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 3 ms 432 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 4 ms 512 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
39 Correct 4 ms 512 KB Output is correct
40 Correct 4 ms 512 KB Output is correct
41 Correct 4 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 4 ms 512 KB Output is correct
44 Correct 4 ms 512 KB Output is correct
45 Correct 4 ms 512 KB Output is correct
46 Correct 4 ms 508 KB Output is correct
47 Correct 4 ms 512 KB Output is correct
48 Correct 863 ms 16860 KB Output is correct
49 Correct 865 ms 16944 KB Output is correct
50 Correct 911 ms 16860 KB Output is correct
51 Correct 892 ms 16856 KB Output is correct
52 Correct 865 ms 16860 KB Output is correct
53 Correct 881 ms 16872 KB Output is correct
54 Correct 912 ms 16872 KB Output is correct
55 Correct 881 ms 16984 KB Output is correct
56 Correct 874 ms 16872 KB Output is correct
57 Correct 997 ms 16864 KB Output is correct
58 Correct 887 ms 16952 KB Output is correct
59 Correct 888 ms 16888 KB Output is correct
60 Correct 867 ms 16848 KB Output is correct
61 Correct 905 ms 17016 KB Output is correct
62 Correct 895 ms 16860 KB Output is correct
63 Correct 863 ms 16864 KB Output is correct
64 Correct 861 ms 16888 KB Output is correct
65 Correct 858 ms 16868 KB Output is correct
66 Correct 857 ms 16988 KB Output is correct
67 Correct 877 ms 17000 KB Output is correct
68 Correct 910 ms 16864 KB Output is correct
69 Correct 896 ms 16860 KB Output is correct
70 Correct 886 ms 16856 KB Output is correct
71 Correct 927 ms 16856 KB Output is correct
72 Correct 871 ms 17000 KB Output is correct
73 Correct 886 ms 16860 KB Output is correct
74 Correct 884 ms 16968 KB Output is correct
75 Correct 874 ms 16872 KB Output is correct
76 Correct 904 ms 16868 KB Output is correct
77 Correct 887 ms 16872 KB Output is correct
78 Correct 887 ms 16860 KB Output is correct
79 Correct 951 ms 16948 KB Output is correct
80 Correct 865 ms 16856 KB Output is correct
81 Correct 883 ms 16908 KB Output is correct
82 Correct 899 ms 16948 KB Output is correct
83 Correct 871 ms 16988 KB Output is correct
84 Correct 895 ms 16856 KB Output is correct
85 Correct 867 ms 16860 KB Output is correct
86 Correct 871 ms 16864 KB Output is correct
87 Correct 882 ms 16864 KB Output is correct
88 Correct 880 ms 16860 KB Output is correct
89 Correct 880 ms 16912 KB Output is correct
90 Correct 916 ms 16952 KB Output is correct
91 Correct 882 ms 16864 KB Output is correct
92 Correct 882 ms 16936 KB Output is correct
93 Correct 891 ms 16860 KB Output is correct
94 Correct 881 ms 16992 KB Output is correct
95 Correct 897 ms 16848 KB Output is correct
96 Correct 898 ms 16948 KB Output is correct
97 Correct 867 ms 16864 KB Output is correct
98 Correct 894 ms 16972 KB Output is correct
99 Correct 871 ms 16872 KB Output is correct
100 Correct 947 ms 16888 KB Output is correct
101 Correct 964 ms 16864 KB Output is correct
102 Correct 968 ms 16860 KB Output is correct
103 Correct 949 ms 16988 KB Output is correct
104 Correct 963 ms 16856 KB Output is correct
105 Correct 932 ms 16984 KB Output is correct
106 Correct 932 ms 16884 KB Output is correct
107 Correct 945 ms 16860 KB Output is correct
108 Correct 927 ms 16896 KB Output is correct
109 Correct 933 ms 16888 KB Output is correct
110 Correct 883 ms 16984 KB Output is correct
111 Correct 904 ms 16872 KB Output is correct
112 Correct 897 ms 16860 KB Output is correct
113 Correct 906 ms 16856 KB Output is correct
114 Correct 898 ms 16860 KB Output is correct
115 Correct 916 ms 16856 KB Output is correct
116 Correct 883 ms 16872 KB Output is correct
117 Correct 886 ms 16988 KB Output is correct
118 Correct 884 ms 16856 KB Output is correct
119 Correct 890 ms 16872 KB Output is correct
120 Correct 2 ms 384 KB Output is correct
121 Correct 2 ms 412 KB Output is correct
122 Correct 879 ms 16864 KB Output is correct
123 Correct 898 ms 16856 KB Output is correct
124 Correct 869 ms 16864 KB Output is correct
125 Correct 863 ms 16872 KB Output is correct
126 Correct 1046 ms 16860 KB Output is correct
127 Correct 906 ms 16860 KB Output is correct
128 Correct 896 ms 16848 KB Output is correct
129 Correct 919 ms 16860 KB Output is correct
130 Correct 876 ms 16872 KB Output is correct
131 Correct 874 ms 16872 KB Output is correct
132 Correct 870 ms 16864 KB Output is correct
133 Correct 889 ms 16856 KB Output is correct