Submission #29073

# Submission time Handle Problem Language Result Execution time Memory
29073 2017-07-18T08:03:45 Z kajebiii Arranging Tickets (JOI17_arranging_tickets) C++14
65 / 100
6000 ms 6464 KB
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi; typedef pair<ll, int> pli; typedef pair<ll, pi> plp;
typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 2e5 + 100, MAX_M = 1e5 + 100, MAX_C = 1e9 + 100;

int N, M; ti Nr[MAX_M];
ll Sum[MAX_N], Temp[MAX_N], maxV;
bool isCan(ll use, ll lim) {
	ll up = lim - use;
	ll cnt = 0;
	priority_queue<pi> Q;
	for(int i=0; i<=N; i++) Temp[i] = 0;
	for(int i=1, j=0; i<=N; i++) {
		Temp[i] += Temp[i-1];
		while(j < M && get<0>(Nr[j]) == i) Q.push(pi(get<1>(Nr[j]), get<2>(Nr[j]))), j++;
		ll now = Sum[i] + Temp[i];
		while(!Q.empty() && now > up) {
			int y, c; tie(y, c) = Q.top(); Q.pop();
			if(y <= i) continue;
			int v = min((ll)c, (now - up + 1) / 2);
			Temp[i] -= 2 * v;
			Temp[y] += 2 * v;
			cnt += v;
			now -= 2 * v;
			if(c - v > 0) Q.push(pi(y, c-v));
		}
		if(now > up) return false;
		if(cnt > use) return false;
	}
	return true;
}
int main() {
	cin >> N >> M;
	for(int i=0; i<M; i++) {
		int x, y, c; scanf("%d%d%d", &x, &y, &c);
		if(x > y) swap(x, y);
		Nr[i] = ti(x, y, c);
		Sum[x] += c; Sum[y] -= c;
	}
	sort(Nr, Nr+M);
	for(int i=1; i<=N; i++) Sum[i] += Sum[i-1], maxV = max(maxV, Sum[i]);

	for(ll i=0; i<=maxV; i++) {
		if(!isCan(maxV-i, i) && isCan(maxV-i+2, i)) {
			printf("what??\n");
		}
	}
	ll ans = -1;
	for(ll l=0, r=maxV; l<=r; ) {
		ll m = (l+r) >> 1;
		if(isCan(maxV-m, m) || isCan(maxV-m+1, m)) ans = m, r = m-1; else l = m+1;
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:47:43: 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);
                                           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6324 KB Output is correct
2 Correct 0 ms 6324 KB Output is correct
3 Correct 0 ms 6324 KB Output is correct
4 Correct 0 ms 6324 KB Output is correct
5 Correct 0 ms 6324 KB Output is correct
6 Correct 0 ms 6324 KB Output is correct
7 Correct 0 ms 6324 KB Output is correct
8 Correct 0 ms 6324 KB Output is correct
9 Correct 0 ms 6324 KB Output is correct
10 Correct 0 ms 6324 KB Output is correct
11 Correct 0 ms 6324 KB Output is correct
12 Correct 0 ms 6324 KB Output is correct
13 Correct 0 ms 6324 KB Output is correct
14 Correct 0 ms 6324 KB Output is correct
15 Correct 0 ms 6324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6324 KB Output is correct
2 Correct 0 ms 6324 KB Output is correct
3 Correct 0 ms 6324 KB Output is correct
4 Correct 0 ms 6324 KB Output is correct
5 Correct 0 ms 6324 KB Output is correct
6 Correct 0 ms 6324 KB Output is correct
7 Correct 0 ms 6324 KB Output is correct
8 Correct 0 ms 6324 KB Output is correct
9 Correct 0 ms 6324 KB Output is correct
10 Correct 0 ms 6324 KB Output is correct
11 Correct 0 ms 6324 KB Output is correct
12 Correct 0 ms 6324 KB Output is correct
13 Correct 0 ms 6324 KB Output is correct
14 Correct 0 ms 6324 KB Output is correct
15 Correct 0 ms 6324 KB Output is correct
16 Correct 3 ms 6324 KB Output is correct
17 Correct 0 ms 6324 KB Output is correct
18 Correct 0 ms 6324 KB Output is correct
19 Correct 3 ms 6324 KB Output is correct
20 Correct 3 ms 6324 KB Output is correct
21 Correct 0 ms 6324 KB Output is correct
22 Correct 0 ms 6324 KB Output is correct
23 Correct 0 ms 6324 KB Output is correct
24 Correct 0 ms 6324 KB Output is correct
25 Correct 0 ms 6324 KB Output is correct
26 Correct 0 ms 6324 KB Output is correct
27 Correct 0 ms 6324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6324 KB Output is correct
2 Correct 0 ms 6324 KB Output is correct
3 Correct 0 ms 6324 KB Output is correct
4 Correct 0 ms 6324 KB Output is correct
5 Correct 0 ms 6324 KB Output is correct
6 Correct 0 ms 6324 KB Output is correct
7 Correct 0 ms 6324 KB Output is correct
8 Correct 0 ms 6324 KB Output is correct
9 Correct 0 ms 6324 KB Output is correct
10 Correct 0 ms 6324 KB Output is correct
11 Correct 0 ms 6324 KB Output is correct
12 Correct 0 ms 6324 KB Output is correct
13 Correct 0 ms 6324 KB Output is correct
14 Correct 0 ms 6324 KB Output is correct
15 Correct 0 ms 6324 KB Output is correct
16 Correct 3 ms 6324 KB Output is correct
17 Correct 0 ms 6324 KB Output is correct
18 Correct 0 ms 6324 KB Output is correct
19 Correct 3 ms 6324 KB Output is correct
20 Correct 3 ms 6324 KB Output is correct
21 Correct 0 ms 6324 KB Output is correct
22 Correct 0 ms 6324 KB Output is correct
23 Correct 0 ms 6324 KB Output is correct
24 Correct 0 ms 6324 KB Output is correct
25 Correct 0 ms 6324 KB Output is correct
26 Correct 0 ms 6324 KB Output is correct
27 Correct 0 ms 6324 KB Output is correct
28 Correct 226 ms 6464 KB Output is correct
29 Correct 249 ms 6464 KB Output is correct
30 Correct 213 ms 6464 KB Output is correct
31 Correct 223 ms 6464 KB Output is correct
32 Correct 223 ms 6464 KB Output is correct
33 Correct 233 ms 6464 KB Output is correct
34 Correct 229 ms 6464 KB Output is correct
35 Correct 199 ms 6464 KB Output is correct
36 Correct 213 ms 6464 KB Output is correct
37 Correct 179 ms 6464 KB Output is correct
38 Correct 6 ms 6464 KB Output is correct
39 Correct 49 ms 6464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6324 KB Output is correct
2 Correct 0 ms 6324 KB Output is correct
3 Correct 0 ms 6324 KB Output is correct
4 Correct 0 ms 6324 KB Output is correct
5 Correct 0 ms 6324 KB Output is correct
6 Correct 0 ms 6324 KB Output is correct
7 Correct 0 ms 6324 KB Output is correct
8 Correct 0 ms 6324 KB Output is correct
9 Correct 0 ms 6324 KB Output is correct
10 Correct 0 ms 6324 KB Output is correct
11 Correct 0 ms 6324 KB Output is correct
12 Correct 0 ms 6324 KB Output is correct
13 Correct 0 ms 6324 KB Output is correct
14 Correct 0 ms 6324 KB Output is correct
15 Correct 0 ms 6324 KB Output is correct
16 Correct 3 ms 6324 KB Output is correct
17 Correct 0 ms 6324 KB Output is correct
18 Correct 0 ms 6324 KB Output is correct
19 Correct 3 ms 6324 KB Output is correct
20 Correct 3 ms 6324 KB Output is correct
21 Correct 0 ms 6324 KB Output is correct
22 Correct 0 ms 6324 KB Output is correct
23 Correct 0 ms 6324 KB Output is correct
24 Correct 0 ms 6324 KB Output is correct
25 Correct 0 ms 6324 KB Output is correct
26 Correct 0 ms 6324 KB Output is correct
27 Correct 0 ms 6324 KB Output is correct
28 Correct 226 ms 6464 KB Output is correct
29 Correct 249 ms 6464 KB Output is correct
30 Correct 213 ms 6464 KB Output is correct
31 Correct 223 ms 6464 KB Output is correct
32 Correct 223 ms 6464 KB Output is correct
33 Correct 233 ms 6464 KB Output is correct
34 Correct 229 ms 6464 KB Output is correct
35 Correct 199 ms 6464 KB Output is correct
36 Correct 213 ms 6464 KB Output is correct
37 Correct 179 ms 6464 KB Output is correct
38 Correct 6 ms 6464 KB Output is correct
39 Correct 49 ms 6464 KB Output is correct
40 Execution timed out 6000 ms 6324 KB Execution timed out
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6324 KB Output is correct
2 Correct 0 ms 6324 KB Output is correct
3 Correct 0 ms 6324 KB Output is correct
4 Correct 0 ms 6324 KB Output is correct
5 Correct 0 ms 6324 KB Output is correct
6 Correct 0 ms 6324 KB Output is correct
7 Correct 0 ms 6324 KB Output is correct
8 Correct 0 ms 6324 KB Output is correct
9 Correct 0 ms 6324 KB Output is correct
10 Correct 0 ms 6324 KB Output is correct
11 Correct 0 ms 6324 KB Output is correct
12 Correct 0 ms 6324 KB Output is correct
13 Correct 0 ms 6324 KB Output is correct
14 Correct 0 ms 6324 KB Output is correct
15 Correct 0 ms 6324 KB Output is correct
16 Correct 3 ms 6324 KB Output is correct
17 Correct 0 ms 6324 KB Output is correct
18 Correct 0 ms 6324 KB Output is correct
19 Correct 3 ms 6324 KB Output is correct
20 Correct 3 ms 6324 KB Output is correct
21 Correct 0 ms 6324 KB Output is correct
22 Correct 0 ms 6324 KB Output is correct
23 Correct 0 ms 6324 KB Output is correct
24 Correct 0 ms 6324 KB Output is correct
25 Correct 0 ms 6324 KB Output is correct
26 Correct 0 ms 6324 KB Output is correct
27 Correct 0 ms 6324 KB Output is correct
28 Correct 226 ms 6464 KB Output is correct
29 Correct 249 ms 6464 KB Output is correct
30 Correct 213 ms 6464 KB Output is correct
31 Correct 223 ms 6464 KB Output is correct
32 Correct 223 ms 6464 KB Output is correct
33 Correct 233 ms 6464 KB Output is correct
34 Correct 229 ms 6464 KB Output is correct
35 Correct 199 ms 6464 KB Output is correct
36 Correct 213 ms 6464 KB Output is correct
37 Correct 179 ms 6464 KB Output is correct
38 Correct 6 ms 6464 KB Output is correct
39 Correct 49 ms 6464 KB Output is correct
40 Execution timed out 6000 ms 6324 KB Execution timed out
41 Halted 0 ms 0 KB -