답안 #284186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284186 2020-08-27T01:39:29 Z ChrisT Pinball (JOI14_pinball) C++17
100 / 100
210 ms 12556 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> xs;
int getx (int x) {return lower_bound(xs.begin(),xs.end(),x) - xs.begin() + 1;}
const int MN = 3e5 + 5; const long long INF = 1e18;
long long tree[MN<<1]; int sz;
void update (int i, long long v) {
	if (v >= tree[i += sz - 1]) return;
	for (tree[i] = v; i > 1; i >>= 1) 
		tree[i>>1] = min(tree[i],tree[i^1]);
}
long long query (int l, int r) {
	long long res = INF;
	for (l+=sz-1,r+=sz;l<r;l>>=1,r>>=1) {
		if (l&1) res = min(res,tree[l++]);
		if (r&1) res = min(res,tree[--r]);
	} 
	return res;
}
int main () {
	int m,n;
	scanf ("%d %d",&m,&n);
	vector<array<int,4>> v(m);
	for (auto &au : v) {
		scanf ("%d %d %d %d",&au[0],&au[1],&au[2],&au[3]);
		xs.push_back(au[0]); xs.push_back(au[1]); xs.push_back(au[2]);
	}
	xs.push_back(1); xs.push_back(n);
	sort(xs.begin(),xs.end()); xs.erase(unique(xs.begin(),xs.end()),xs.end());
	sz = xs.size();
	long long ans = INF; vector<long long> mn(m);
	for (int i = 1; i < (sz << 1); i++) tree[i] = INF;
	update(getx(1),0);
	for (int i = 0; i < m; i++) {
		v[i][0] = getx(v[i][0]); v[i][1] = getx(v[i][1]); v[i][2] = getx(v[i][2]);
		mn[i] = query(v[i][0],v[i][1]);
		update(v[i][2],mn[i] + v[i][3]);
	}
	for (int i = 1; i < (sz << 1); i++) tree[i] = INF;
	update(getx(n),0);
	for (int i = 0; i < m; i++) {
		long long go = query(v[i][0],v[i][1]) + v[i][3];
		ans = min(ans,go + mn[i]);
		update(v[i][2],go);
	}
	if (ans >= INF/2) ans = -1;
	printf ("%lld\n",ans);
	return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |  scanf ("%d %d",&m,&n);
      |  ~~~~~~^~~~~~~~~~~~~~~
pinball.cpp:25:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |   scanf ("%d %d %d %d",&au[0],&au[1],&au[2],&au[3]);
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 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 1 ms 384 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 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 1 ms 384 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 15 ms 1280 KB Output is correct
26 Correct 41 ms 2936 KB Output is correct
27 Correct 122 ms 7020 KB Output is correct
28 Correct 124 ms 7656 KB Output is correct
29 Correct 87 ms 5484 KB Output is correct
30 Correct 154 ms 8040 KB Output is correct
31 Correct 193 ms 10500 KB Output is correct
32 Correct 196 ms 9704 KB Output is correct
33 Correct 23 ms 2684 KB Output is correct
34 Correct 83 ms 6380 KB Output is correct
35 Correct 118 ms 12556 KB Output is correct
36 Correct 210 ms 12520 KB Output is correct
37 Correct 161 ms 12392 KB Output is correct
38 Correct 159 ms 12396 KB Output is correct