Submission #79002

# Submission time Handle Problem Language Result Execution time Memory
79002 2018-10-10T07:24:48 Z Plurm Pinball (JOI14_pinball) C++11
100 / 100
485 ms 74036 KB
#include <bits/stdc++.h>
using namespace std;
const int MXN = 1 << 17;
long long dp1[MXN];
long long dp2[MXN];
long long dp1h[3*MXN];
long long dp2h[3*MXN];
long long segT1[12*MXN];
long long segT2[12*MXN];
int lb[12*MXN];
int rb[12*MXN];
void build(int c,int l,int r){
	lb[c] = l;
	rb[c] = r;
	if(l == r){
		segT1[c] = dp1h[l];
		segT2[c] = dp2h[l];
		return;
	}
	int k = (l+r)/2;
	build(2*c,l,k);
	build(2*c+1,k+1,r);
	segT1[c] = min(segT1[2*c],segT1[2*c+1]);
	segT2[c] = min(segT2[2*c],segT2[2*c+1]);
}
void update1(int c,int idx){
	if(lb[c] == rb[c]){
		segT1[c] = dp1h[idx];
		return;
	}
	int k = (lb[c] + rb[c])/2;
	if(idx <= k){
		update1(2*c,idx);
	}else{
		update1(2*c+1,idx);
	}
	segT1[c] = min(segT1[2*c],segT1[2*c+1]);
}
void update2(int c,int idx){
	if(lb[c] == rb[c]){
		segT2[c] = dp2h[idx];
		return;
	}
	int k = (lb[c] + rb[c])/2;
	if(idx <= k){
		update2(2*c,idx);
	}else{
		update2(2*c+1,idx);
	}
	segT2[c] = min(segT2[2*c],segT2[2*c+1]);
}
long long query1(int c,int l,int r){
	if(lb[c] == l && rb[c] == r) return segT1[c];
	int k = (lb[c] + rb[c])/2;
	if(l <= k && k < r){
		return min(query1(2*c,l,k),query1(2*c+1,k+1,r));
	}else if(r <= k){
		return query1(2*c,l,r);
	}else{
		return query1(2*c+1,l,r);
	}
}
long long query2(int c,int l,int r){
	if(lb[c] == l && rb[c] == r) return segT2[c];
	int k = (lb[c] + rb[c])/2;
	if(l <= k && k < r){
		return min(query2(2*c,l,k),query2(2*c+1,k+1,r));
	}else if(r <= k){
		return query2(2*c,l,r);
	}else{
		return query2(2*c+1,l,r);
	}
}
int main(){
	int m,n;
	scanf("%d%d",&m,&n);
	vector<tuple<int,int,int,int> > data;
	vector<int> cprs;
	for(int i = 0; i < m; i++){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		data.emplace_back(a,b,c,d);
		cprs.push_back(a);
		cprs.push_back(b);
		cprs.push_back(c);
		dp1[i] = dp2[i] = 1e18;
	}
	sort(cprs.begin(),cprs.end());
	cprs.resize(unique(cprs.begin(),cprs.end()) - cprs.begin());
	for(int i = 0; i < cprs.size(); i++){
		dp1h[i] = dp2h[i] = 1e18;
	}
	build(1,0,cprs.size()-1);
	for(int i = 0; i < m; i++){
		int idx = lower_bound(cprs.begin(),cprs.end(),get<2>(data[i])) - cprs.begin();
		if(get<0>(data[i]) == 1){
			dp1[i] = get<3>(data[i]);
			dp1h[idx] = min(dp1h[idx],dp1[i]);
			update1(1,idx);
		}
		if(get<1>(data[i]) == n){
			dp2[i] = get<3>(data[i]);
			dp2h[idx] = min(dp2h[idx],dp2[i]);
			update2(1,idx);
		}
		dp1[i] = min(dp1[i],(long long)get<3>(data[i]) + query1(1,
			lower_bound(cprs.begin(),cprs.end(),
				get<0>(data[i])) - cprs.begin(),
			lower_bound(cprs.begin(),cprs.end(),
				get<1>(data[i])) - cprs.begin())
		);
		dp1h[idx] = min(dp1h[idx],dp1[i]);
		update1(1,idx);

		dp2[i] = min(dp2[i],(long long)get<3>(data[i]) + query2(1,
			lower_bound(cprs.begin(),cprs.end(),
				get<0>(data[i])) - cprs.begin(),
			lower_bound(cprs.begin(),cprs.end(),
				get<1>(data[i])) - cprs.begin())
		);
		dp2h[idx] = min(dp2h[idx],dp2[i]);
		update2(1,idx);
		
	}
	long long mn = 1e18;
	for(int i = 0; i < m; i++){
		mn = min(mn,dp1[i] + dp2[i] - get<3>(data[i]));
	}
	if(mn == 1e18){
		printf("-1\n");
	}else{
		printf("%lld\n",mn);
	}
	return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:90:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < cprs.size(); i++){
                 ~~^~~~~~~~~~~~~
pinball.cpp:76: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:81:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d",&a,&b,&c,&d);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 728 KB Output is correct
12 Correct 2 ms 744 KB Output is correct
13 Correct 2 ms 744 KB Output is correct
14 Correct 2 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 728 KB Output is correct
12 Correct 2 ms 744 KB Output is correct
13 Correct 2 ms 744 KB Output is correct
14 Correct 2 ms 744 KB Output is correct
15 Correct 2 ms 744 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 4 ms 764 KB Output is correct
18 Correct 3 ms 764 KB Output is correct
19 Correct 4 ms 892 KB Output is correct
20 Correct 4 ms 932 KB Output is correct
21 Correct 3 ms 1020 KB Output is correct
22 Correct 4 ms 1216 KB Output is correct
23 Correct 4 ms 1252 KB Output is correct
24 Correct 4 ms 1292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 728 KB Output is correct
12 Correct 2 ms 744 KB Output is correct
13 Correct 2 ms 744 KB Output is correct
14 Correct 2 ms 744 KB Output is correct
15 Correct 2 ms 744 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 4 ms 764 KB Output is correct
18 Correct 3 ms 764 KB Output is correct
19 Correct 4 ms 892 KB Output is correct
20 Correct 4 ms 932 KB Output is correct
21 Correct 3 ms 1020 KB Output is correct
22 Correct 4 ms 1216 KB Output is correct
23 Correct 4 ms 1252 KB Output is correct
24 Correct 4 ms 1292 KB Output is correct
25 Correct 44 ms 3632 KB Output is correct
26 Correct 81 ms 7372 KB Output is correct
27 Correct 249 ms 15712 KB Output is correct
28 Correct 197 ms 15712 KB Output is correct
29 Correct 189 ms 20376 KB Output is correct
30 Correct 269 ms 20684 KB Output is correct
31 Correct 415 ms 37712 KB Output is correct
32 Correct 368 ms 37712 KB Output is correct
33 Correct 47 ms 37712 KB Output is correct
34 Correct 189 ms 41760 KB Output is correct
35 Correct 282 ms 62372 KB Output is correct
36 Correct 485 ms 66292 KB Output is correct
37 Correct 403 ms 70164 KB Output is correct
38 Correct 386 ms 74036 KB Output is correct