답안 #46853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46853 2018-04-23T19:20:22 Z qoo2p5 Bulldozer (JOI17_bulldozer) C++17
80 / 100
962 ms 63272 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 1e6;
const ll LINF = (ll) 1e18 + 1e9;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; ++(i))
#define per(i, f, t) for (auto i = (f); i >= (t); --(i))

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

void add(ll &x, ll y) {
    x += y;
    if (x >= MOD) x -= MOD;
    if (x < 0) x += MOD;
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

#define double long double

const int N = 1 << 11;
const double EPS = 1e-15;

struct P {
	ll x, y, c;
};

int n;
P p[N];

struct Ev {
	int a, b;
	double ang;
	
	Ev(int a, int b) : a(a), b(b) {
		if (p[a].x == p[b].x) {
			ang = 1e10;
		} else {
			ang = (double) (p[a].y - p[b].y) / (p[a].x - p[b].x);
		}
	}
};

bool operator<(const Ev &u, const Ev &v) {
	if (u.ang + EPS < v.ang) {
		return 1;
	}
	if (u.ang - EPS > v.ang) {
		return 0;
	}
	
	return mp(u.a, u.b) < mp(v.a, v.b);
}

struct Node {
	ll sum, res, left, right;
};

Node tree[2 * N + 13];

void upd(int i, ll val) {
	i += N;
	tree[i] = {val, max(0LL, val), max(0LL, val), max(0LL, val)};
	i /= 2;
	while (i > 0) {
		tree[i].sum = tree[2 * i].sum + tree[2 * i + 1].sum;
		tree[i].left = max(tree[2 * i].left, tree[2 * i].sum + tree[2 * i + 1].left);
		tree[i].right = max(tree[2 * i + 1].right, tree[2 * i + 1].sum + tree[2 * i].right);
		tree[i].res = max(tree[2 * i].right + tree[2 * i + 1].left, max(tree[2 * i].res, tree[2 * i + 1].res));
		i /= 2;
	}
}

ll get() {
	return tree[1].res;
}

int pos[N];

void make(const Ev &ev) {
	int a = pos[ev.a];
	int b = pos[ev.b];
	assert(a + 1 == b);
	swap(pos[ev.a], pos[ev.b]);
	ll va = tree[N + a].sum;
	ll vb = tree[N + b].sum;
	upd(a, vb);
	upd(b, va);
}

void run() {
	cin >> n;
	rep(i, 0, n) {
		cin >> p[i].x >> p[i].y >> p[i].c;
	}
	sort(p, p + n, [] (const auto &a, const auto &b) {
		return mp(a.x, a.y) < mp(b.x, b.y);
	});
	vector<Ev> events;
	events.reserve(n * (n - 1) / 2);
	rep(i, 0, n) {
		rep(j, i + 1, n) {
			events.pb(Ev(i, j));
		}
	}
	sort(all(events));
	
	ll ans = 0;
	rep(i, 0, n) {
		upd(i, p[i].c);
		pos[i] = i;
	}
	
	maxi(ans, get());
	
	rep(i, 0, sz(events)) {
		make(events[i]);
		int j = i;
		while (j + 1 < sz(events) && abs(events[j].ang - events[j + 1].ang) < EPS) {
			j++;
			make(events[j]);
		}
		
		maxi(ans, get());
		i = j;
	}
	
	cout << ans << "\n";
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(TASK ".in", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bulldozer.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(TASK ".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 3 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 4 ms 560 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 3 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 640 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 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 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 640 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 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 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 908 ms 63164 KB Output is correct
34 Correct 850 ms 63188 KB Output is correct
35 Correct 851 ms 63096 KB Output is correct
36 Correct 838 ms 63168 KB Output is correct
37 Correct 872 ms 63176 KB Output is correct
38 Correct 847 ms 63204 KB Output is correct
39 Correct 867 ms 63172 KB Output is correct
40 Correct 877 ms 63168 KB Output is correct
41 Correct 848 ms 63164 KB Output is correct
42 Correct 844 ms 63168 KB Output is correct
43 Correct 852 ms 63160 KB Output is correct
44 Correct 846 ms 63176 KB Output is correct
45 Correct 841 ms 63164 KB Output is correct
46 Correct 871 ms 63164 KB Output is correct
47 Correct 853 ms 63100 KB Output is correct
48 Correct 859 ms 63168 KB Output is correct
49 Correct 859 ms 63172 KB Output is correct
50 Correct 851 ms 63164 KB Output is correct
51 Correct 843 ms 63168 KB Output is correct
52 Correct 842 ms 63160 KB Output is correct
53 Correct 897 ms 63172 KB Output is correct
54 Correct 857 ms 63164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 640 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 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 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 908 ms 63164 KB Output is correct
34 Correct 850 ms 63188 KB Output is correct
35 Correct 851 ms 63096 KB Output is correct
36 Correct 838 ms 63168 KB Output is correct
37 Correct 872 ms 63176 KB Output is correct
38 Correct 847 ms 63204 KB Output is correct
39 Correct 867 ms 63172 KB Output is correct
40 Correct 877 ms 63168 KB Output is correct
41 Correct 848 ms 63164 KB Output is correct
42 Correct 844 ms 63168 KB Output is correct
43 Correct 852 ms 63160 KB Output is correct
44 Correct 846 ms 63176 KB Output is correct
45 Correct 841 ms 63164 KB Output is correct
46 Correct 871 ms 63164 KB Output is correct
47 Correct 853 ms 63100 KB Output is correct
48 Correct 859 ms 63168 KB Output is correct
49 Correct 859 ms 63172 KB Output is correct
50 Correct 851 ms 63164 KB Output is correct
51 Correct 843 ms 63168 KB Output is correct
52 Correct 842 ms 63160 KB Output is correct
53 Correct 897 ms 63172 KB Output is correct
54 Correct 857 ms 63164 KB Output is correct
55 Correct 874 ms 63164 KB Output is correct
56 Correct 862 ms 63224 KB Output is correct
57 Correct 856 ms 63164 KB Output is correct
58 Correct 844 ms 63164 KB Output is correct
59 Correct 857 ms 63100 KB Output is correct
60 Correct 856 ms 63224 KB Output is correct
61 Correct 860 ms 63224 KB Output is correct
62 Correct 863 ms 63224 KB Output is correct
63 Correct 865 ms 63164 KB Output is correct
64 Correct 849 ms 63096 KB Output is correct
65 Correct 844 ms 63224 KB Output is correct
66 Correct 874 ms 63224 KB Output is correct
67 Correct 860 ms 63168 KB Output is correct
68 Correct 949 ms 63172 KB Output is correct
69 Correct 877 ms 63272 KB Output is correct
70 Correct 872 ms 63172 KB Output is correct
71 Correct 851 ms 63172 KB Output is correct
72 Correct 879 ms 63176 KB Output is correct
73 Correct 868 ms 63168 KB Output is correct
74 Correct 907 ms 63164 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 3 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 4 ms 560 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 3 ms 512 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 3 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 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 3 ms 512 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
45 Correct 4 ms 512 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 908 ms 63164 KB Output is correct
49 Correct 850 ms 63188 KB Output is correct
50 Correct 851 ms 63096 KB Output is correct
51 Correct 838 ms 63168 KB Output is correct
52 Correct 872 ms 63176 KB Output is correct
53 Correct 847 ms 63204 KB Output is correct
54 Correct 867 ms 63172 KB Output is correct
55 Correct 877 ms 63168 KB Output is correct
56 Correct 848 ms 63164 KB Output is correct
57 Correct 844 ms 63168 KB Output is correct
58 Correct 852 ms 63160 KB Output is correct
59 Correct 846 ms 63176 KB Output is correct
60 Correct 841 ms 63164 KB Output is correct
61 Correct 871 ms 63164 KB Output is correct
62 Correct 853 ms 63100 KB Output is correct
63 Correct 859 ms 63168 KB Output is correct
64 Correct 859 ms 63172 KB Output is correct
65 Correct 851 ms 63164 KB Output is correct
66 Correct 843 ms 63168 KB Output is correct
67 Correct 842 ms 63160 KB Output is correct
68 Correct 897 ms 63172 KB Output is correct
69 Correct 857 ms 63164 KB Output is correct
70 Correct 874 ms 63164 KB Output is correct
71 Correct 862 ms 63224 KB Output is correct
72 Correct 856 ms 63164 KB Output is correct
73 Correct 844 ms 63164 KB Output is correct
74 Correct 857 ms 63100 KB Output is correct
75 Correct 856 ms 63224 KB Output is correct
76 Correct 860 ms 63224 KB Output is correct
77 Correct 863 ms 63224 KB Output is correct
78 Correct 865 ms 63164 KB Output is correct
79 Correct 849 ms 63096 KB Output is correct
80 Correct 844 ms 63224 KB Output is correct
81 Correct 874 ms 63224 KB Output is correct
82 Correct 860 ms 63168 KB Output is correct
83 Correct 949 ms 63172 KB Output is correct
84 Correct 877 ms 63272 KB Output is correct
85 Correct 872 ms 63172 KB Output is correct
86 Correct 851 ms 63172 KB Output is correct
87 Correct 879 ms 63176 KB Output is correct
88 Correct 868 ms 63168 KB Output is correct
89 Correct 907 ms 63164 KB Output is correct
90 Correct 901 ms 63164 KB Output is correct
91 Correct 875 ms 63164 KB Output is correct
92 Correct 871 ms 63168 KB Output is correct
93 Correct 866 ms 63164 KB Output is correct
94 Correct 876 ms 63096 KB Output is correct
95 Correct 867 ms 63224 KB Output is correct
96 Correct 876 ms 63096 KB Output is correct
97 Correct 860 ms 63164 KB Output is correct
98 Correct 844 ms 63244 KB Output is correct
99 Correct 863 ms 63168 KB Output is correct
100 Correct 881 ms 63172 KB Output is correct
101 Correct 875 ms 63168 KB Output is correct
102 Correct 886 ms 63180 KB Output is correct
103 Correct 894 ms 63172 KB Output is correct
104 Correct 856 ms 63164 KB Output is correct
105 Correct 872 ms 63164 KB Output is correct
106 Correct 867 ms 63156 KB Output is correct
107 Correct 859 ms 63272 KB Output is correct
108 Correct 843 ms 63168 KB Output is correct
109 Correct 861 ms 63164 KB Output is correct
110 Correct 915 ms 63096 KB Output is correct
111 Correct 913 ms 63224 KB Output is correct
112 Correct 920 ms 63272 KB Output is correct
113 Correct 899 ms 63164 KB Output is correct
114 Correct 916 ms 63168 KB Output is correct
115 Correct 962 ms 63168 KB Output is correct
116 Correct 945 ms 63176 KB Output is correct
117 Correct 922 ms 63160 KB Output is correct
118 Correct 909 ms 63196 KB Output is correct
119 Correct 924 ms 63224 KB Output is correct
120 Incorrect 2 ms 384 KB Output isn't correct
121 Halted 0 ms 0 KB -