답안 #118647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118647 2019-06-19T10:14:25 Z roseanne_pcy Pinball (JOI14_pinball) C++14
100 / 100
631 ms 138724 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

const int maxn = 1e5+5;
int n, m;

int A[maxn], B[maxn], C[maxn], pay[maxn];
vector<int> cut;
map<int, int> bst;

struct node
{
	ll L, R, fill;
	node() : L(1e18), R(1e18), fill(1e18){}
	node(ll L, ll R, ll fill) : L(L), R(R), fill(fill){}
};

node st[50*maxn];
int cnt;

node pull(node x, node y)
{
	node a;
	a.L = min(x.L, y.L);
	a.R = min(x.R, y.R);
	a.fill = min(x.fill, y.fill);
	return a;
}

void build(int p = 1, int L = 1, int R = cnt)
{
	if(L == R) 
	{
		st[p] = node();
		return;
	}
	int M = (L+R)/2;
	build(2*p, L, M);
	build(2*p+1, M+1, R);
	st[p] = pull(st[2*p], st[2*p+1]);
}

node ask(int i, int j, int p = 1, int L = 1, int R = cnt)
{
	if(i> R || j< L) return node();
	if(i<= L && R<= j) return st[p];
	int M = (L+R)/2;
	node x = ask(i, j, 2*p, L, M);
	node y = ask(i, j, 2*p+1, M+1, R);
	node res = pull(x, y);
	return res;
}

void update(int x, node dx, int p = 1, int L = 1, int R = cnt)
{
	if(L == R)
	{
		node res = pull(dx, st[p]);
		st[p] = res;
		return;
	}
	int M = (L+R)/2;
	if(x<= M) update(x, dx, 2*p, L, M);
	else update(x, dx, 2*p+1, M+1, R);
	st[p] = pull(st[2*p], st[2*p+1]);
}

int main()
{
	scanf("%d %d", &n, &m);
	for(int i = 1; i<= n; i++)
	{
		scanf("%d %d %d %d", &A[i], &B[i], &C[i], &pay[i]);
		cut.pb(A[i]); cut.pb(B[i]); cut.pb(C[i]);
	}
	sort(cut.begin(), cut.end());
	cut.resize(unique(cut.begin(), cut.end())-cut.begin());
	if(cut[0] != 1) cnt++;
	for(int i = 0; i+1< (int) cut.size(); i++)
	{
		int x = cut[i];
		cnt++;
		bst[x] = cnt;
		if(x+1 != cut[i+1]) cnt++;
	}
	cnt++;
	bst[cut.back()] = cnt;
	if(cut.back() != m) cnt++;
	for(int i = 1; i<= n; i++)
	{
		A[i] = bst[A[i]];
		B[i] = bst[B[i]];
		C[i] = bst[C[i]];
		assert(A[i] && B[i] && C[i]);
	}
	build();
	ll best = 1e18;
	for(int i = 1; i<= n; i++)
	{
		node que = ask(A[i], B[i]);
		node res;
		res.L = que.L+pay[i];
		if(A[i] == 1) res.L = min(res.L, 1LL*pay[i]);
		res.R = que.R+pay[i];
		if(B[i] == cnt) res.R = min(res.R, 1LL*pay[i]);
		res.fill = que.fill+pay[i];
		if(A[i] == 1 && B[i] == cnt) res.fill = min(res.fill, 1LL*pay[i]);
		if(A[i] == 1) res.fill = min(res.fill, pay[i]+que.R);
		if(B[i] == cnt) res.fill = min(res.fill, pay[i]+que.L);
		res.fill = min(res.fill, pay[i]+que.L+que.R);
		update(C[i], res);
		// printf("{%lld %lld %lld}\n", res.L, res.R, res.fill);
		best = min(best, res.fill);
	}
	if(best == 1e18) printf("-1\n");
	else printf("%lld\n", best);
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
pinball.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d %d", &A[i], &B[i], &C[i], &pay[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 117752 KB Output is correct
2 Correct 90 ms 117880 KB Output is correct
3 Correct 91 ms 117752 KB Output is correct
4 Correct 90 ms 117752 KB Output is correct
5 Correct 92 ms 117880 KB Output is correct
6 Correct 89 ms 117752 KB Output is correct
7 Correct 90 ms 117796 KB Output is correct
8 Correct 89 ms 117700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 117752 KB Output is correct
2 Correct 90 ms 117880 KB Output is correct
3 Correct 91 ms 117752 KB Output is correct
4 Correct 90 ms 117752 KB Output is correct
5 Correct 92 ms 117880 KB Output is correct
6 Correct 89 ms 117752 KB Output is correct
7 Correct 90 ms 117796 KB Output is correct
8 Correct 89 ms 117700 KB Output is correct
9 Correct 93 ms 117756 KB Output is correct
10 Correct 94 ms 117792 KB Output is correct
11 Correct 93 ms 117752 KB Output is correct
12 Correct 93 ms 117752 KB Output is correct
13 Correct 94 ms 117724 KB Output is correct
14 Correct 92 ms 117760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 117752 KB Output is correct
2 Correct 90 ms 117880 KB Output is correct
3 Correct 91 ms 117752 KB Output is correct
4 Correct 90 ms 117752 KB Output is correct
5 Correct 92 ms 117880 KB Output is correct
6 Correct 89 ms 117752 KB Output is correct
7 Correct 90 ms 117796 KB Output is correct
8 Correct 89 ms 117700 KB Output is correct
9 Correct 93 ms 117756 KB Output is correct
10 Correct 94 ms 117792 KB Output is correct
11 Correct 93 ms 117752 KB Output is correct
12 Correct 93 ms 117752 KB Output is correct
13 Correct 94 ms 117724 KB Output is correct
14 Correct 92 ms 117760 KB Output is correct
15 Correct 92 ms 117752 KB Output is correct
16 Correct 93 ms 117752 KB Output is correct
17 Correct 96 ms 117880 KB Output is correct
18 Correct 93 ms 117728 KB Output is correct
19 Correct 93 ms 118136 KB Output is correct
20 Correct 95 ms 118008 KB Output is correct
21 Correct 92 ms 117880 KB Output is correct
22 Correct 96 ms 118008 KB Output is correct
23 Correct 92 ms 117880 KB Output is correct
24 Correct 94 ms 118008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 117752 KB Output is correct
2 Correct 90 ms 117880 KB Output is correct
3 Correct 91 ms 117752 KB Output is correct
4 Correct 90 ms 117752 KB Output is correct
5 Correct 92 ms 117880 KB Output is correct
6 Correct 89 ms 117752 KB Output is correct
7 Correct 90 ms 117796 KB Output is correct
8 Correct 89 ms 117700 KB Output is correct
9 Correct 93 ms 117756 KB Output is correct
10 Correct 94 ms 117792 KB Output is correct
11 Correct 93 ms 117752 KB Output is correct
12 Correct 93 ms 117752 KB Output is correct
13 Correct 94 ms 117724 KB Output is correct
14 Correct 92 ms 117760 KB Output is correct
15 Correct 92 ms 117752 KB Output is correct
16 Correct 93 ms 117752 KB Output is correct
17 Correct 96 ms 117880 KB Output is correct
18 Correct 93 ms 117728 KB Output is correct
19 Correct 93 ms 118136 KB Output is correct
20 Correct 95 ms 118008 KB Output is correct
21 Correct 92 ms 117880 KB Output is correct
22 Correct 96 ms 118008 KB Output is correct
23 Correct 92 ms 117880 KB Output is correct
24 Correct 94 ms 118008 KB Output is correct
25 Correct 114 ms 119012 KB Output is correct
26 Correct 175 ms 121036 KB Output is correct
27 Correct 326 ms 124536 KB Output is correct
28 Correct 218 ms 121328 KB Output is correct
29 Correct 283 ms 123368 KB Output is correct
30 Correct 286 ms 121320 KB Output is correct
31 Correct 543 ms 128432 KB Output is correct
32 Correct 517 ms 126284 KB Output is correct
33 Correct 144 ms 121228 KB Output is correct
34 Correct 306 ms 126328 KB Output is correct
35 Correct 399 ms 134628 KB Output is correct
36 Correct 631 ms 138600 KB Output is correct
37 Correct 573 ms 138724 KB Output is correct
38 Correct 523 ms 138596 KB Output is correct