답안 #56762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
56762 2018-07-12T12:50:19 Z RezwanArefin01 Pinball (JOI14_pinball) C++17
51 / 100
1000 ms 42588 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii; 

const int N = 1e5 + 10; 
int n, m, a[N], b[N], c[N], d[N]; 
ll fl[N], fr[N], t[N * 12]; 

void update(int node, int l, int r, int i, ll v) {
	if(l == r) {
		t[node] = min(t[node], v); 
		return;
	} int m = l + r >> 1; 
	if(i <= m) update(node << 1, l, m, i, v); 
	else update(node << 1 | 1, m + 1, r, i, v); 
	t[node] = min(t[node << 1], t[node << 1 | 1]); 
}

ll query(int node, int l, int r, int i, int j) {
	if(r < i || l > j) return 1e15; 
	if(i <= l && r <= j) return t[node];
	int m = l + r >> 1; 
	return min(query(node << 1, l, m, i, j), 
			query(node << 1 | 1, m + 1, r, i, j)); 
}

int main(int argc, char const *argv[]) {
	scanf("%d %d", &m, &n); 
	vector<int> v;
	for(int i = 1; i <= m; i++) {
		scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]); 
		v.push_back(a[i]);
		v.push_back(b[i]);
		v.push_back(c[i]); 
	}	
	sort(v.begin(), v.end()); 
	v.erase(unique(v.begin(), v.end()), v.end());
	map<int, int> mp, rev; 

	for(int i = 0; i < v.size(); i++) {
		mp[v[i]] = i + 1; 
		rev[i + 1] = v[i]; 
	}
	for(int i = 1; i <= m; i++) {
		a[i] = mp[a[i]]; 
		b[i] = mp[b[i]]; 
		c[i] = mp[c[i]];
	}
	int L = mp.size() + 1; 
	for(int i = 0; i < 4 * L; i++) t[i] = 1e15; 
	for(int i = 1; i <= m; i++) {
		if(rev[a[i]] == 1) fl[i] = d[i]; 
		else fl[i] = query(1, 1, L, a[i], b[i]) + d[i]; 
		update(1, 1, L, c[i], fl[i]); 
	}
	for(int i = 0; i < 4 * L; i++) t[i] = 1e15; 
	for(int i = 1; i <= m; i++) {
		if(rev[b[i]] == n) fr[i] = d[i]; 
		else fr[i] = query(1, 1, L, a[i], b[i]) + d[i]; 
		update(1, 1, L, c[i], fr[i]);
	}
	ll ans = 1e18; 
	for(int i = 1; i <= m; i++) {
		ans = min(ans, fl[i] + fr[i] - d[i]); 
	}
	if(ans > 1e15) ans = -1; 
	printf("%lld\n", ans);
}

Compilation message

pinball.cpp: In function 'void update(int, int, int, int, ll)':
pinball.cpp:15:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  } int m = l + r >> 1; 
            ~~^~~
pinball.cpp: In function 'll query(int, int, int, int, int)':
pinball.cpp:24:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m = l + r >> 1; 
          ~~^~~
pinball.cpp: In function 'int main(int, const char**)':
pinball.cpp:42:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++) {
                 ~~^~~~~~~~~~
pinball.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &m, &n); 
  ~~~~~^~~~~~~~~~~~~~~~~
pinball.cpp:33: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], &d[i]); 
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 676 KB Output is correct
10 Correct 3 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 4 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 3 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 676 KB Output is correct
10 Correct 3 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 4 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 3 ms 676 KB Output is correct
15 Correct 2 ms 676 KB Output is correct
16 Correct 3 ms 676 KB Output is correct
17 Correct 6 ms 824 KB Output is correct
18 Correct 4 ms 824 KB Output is correct
19 Correct 4 ms 996 KB Output is correct
20 Correct 4 ms 996 KB Output is correct
21 Correct 3 ms 996 KB Output is correct
22 Correct 5 ms 1020 KB Output is correct
23 Correct 5 ms 1020 KB Output is correct
24 Correct 5 ms 1020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 676 KB Output is correct
10 Correct 3 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 4 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 3 ms 676 KB Output is correct
15 Correct 2 ms 676 KB Output is correct
16 Correct 3 ms 676 KB Output is correct
17 Correct 6 ms 824 KB Output is correct
18 Correct 4 ms 824 KB Output is correct
19 Correct 4 ms 996 KB Output is correct
20 Correct 4 ms 996 KB Output is correct
21 Correct 3 ms 996 KB Output is correct
22 Correct 5 ms 1020 KB Output is correct
23 Correct 5 ms 1020 KB Output is correct
24 Correct 5 ms 1020 KB Output is correct
25 Correct 43 ms 3172 KB Output is correct
26 Correct 155 ms 8668 KB Output is correct
27 Correct 537 ms 16352 KB Output is correct
28 Correct 195 ms 16352 KB Output is correct
29 Correct 333 ms 16352 KB Output is correct
30 Correct 348 ms 16352 KB Output is correct
31 Correct 765 ms 25900 KB Output is correct
32 Correct 695 ms 25900 KB Output is correct
33 Correct 93 ms 25900 KB Output is correct
34 Correct 410 ms 25900 KB Output is correct
35 Correct 615 ms 42424 KB Output is correct
36 Correct 994 ms 42580 KB Output is correct
37 Execution timed out 1089 ms 42588 KB Time limit exceeded
38 Halted 0 ms 0 KB -