Submission #227123

# Submission time Handle Problem Language Result Execution time Memory
227123 2020-04-26T06:57:13 Z arnold518 Pinball (JOI14_pinball) C++14
100 / 100
292 ms 16996 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;
const int MAXM = 3e5;
const ll INF = 1e18;

int N, M;
int L[MAXN+10], R[MAXN+10], P[MAXN+10], D[MAXN+10];

ll tree[MAXM*4+10];
void init(int node, int tl, int tr)
{
	tree[node]=INF;
	if(tl==tr) return;
	int mid=tl+tr>>1;
	init(node*2, tl, mid);
	init(node*2+1, mid+1, tr);
}

void update(int node, int tl, int tr, int p, ll v)
{
	if(tl==tr)
	{
		tree[node]=min(tree[node], v);
		return;
	}
	int mid=tl+tr>>1;
	if(p<=mid) update(node*2, tl, mid, p, v);
	else update(node*2+1, mid+1, tr, p, v);
	tree[node]=min(tree[node*2], tree[node*2+1]);
}

ll query(int node, int tl, int tr, int l, int r)
{
	if(l<=tl && tr<=r) return tree[node];
	if(r<tl || tr<l) return INF;
	int mid=tl+tr>>1;
	return min(query(node*2, tl, mid, l, r), query(node*2+1, mid+1, tr, l, r));
}

ll dp1[MAXN+10], dp2[MAXN+10];

int main()
{
	int i, j;

	scanf("%d%d", &N, &M);

	vector<int> comp;
	comp.push_back(1); comp.push_back(M);
	for(i=1; i<=N; i++)
	{
		scanf("%d%d%d%d", &L[i], &R[i], &P[i], &D[i]);
		comp.push_back(L[i]);
		comp.push_back(R[i]);
		comp.push_back(P[i]);
	}
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	M=comp.size();
	for(i=1; i<=N; i++)
	{
		L[i]=lower_bound(comp.begin(), comp.end(), L[i])-comp.begin()+1;
		R[i]=lower_bound(comp.begin(), comp.end(), R[i])-comp.begin()+1;
		P[i]=lower_bound(comp.begin(), comp.end(), P[i])-comp.begin()+1;
	}

	init(1, 1, M);
	update(1, 1, M, 1, 0);
	for(i=1; i<=N; i++)
	{
		dp1[i]=query(1, 1, M, L[i], R[i])+D[i];
		update(1, 1, M, P[i], dp1[i]);
	}

	init(1, 1, M);
	update(1, 1, M, M, 0);
	for(i=1; i<=N; i++)
	{
		dp2[i]=query(1, 1, M, L[i], R[i])+D[i];
		update(1, 1, M, P[i], dp2[i]);
	}

	ll ans=INF;
	for(i=1; i<=N; i++) ans=min(ans, dp1[i]+dp2[i]-D[i]);
	if(ans==INF) ans=-1;
	printf("%lld\n", ans);
}

Compilation message

pinball.cpp: In function 'void init(int, int, int)':
pinball.cpp:20:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
pinball.cpp: In function 'void update(int, int, int, int, ll)':
pinball.cpp:32:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
pinball.cpp: In function 'll query(int, int, int, int, int)':
pinball.cpp:42:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
pinball.cpp: In function 'int main()':
pinball.cpp:50:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
pinball.cpp:52: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:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &L[i], &R[i], &P[i], &D[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 7 ms 512 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 7 ms 512 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 24 ms 1664 KB Output is correct
26 Correct 60 ms 3440 KB Output is correct
27 Correct 175 ms 8224 KB Output is correct
28 Correct 170 ms 8548 KB Output is correct
29 Correct 125 ms 6764 KB Output is correct
30 Correct 213 ms 9188 KB Output is correct
31 Correct 253 ms 12772 KB Output is correct
32 Correct 247 ms 10724 KB Output is correct
33 Correct 39 ms 3060 KB Output is correct
34 Correct 126 ms 8812 KB Output is correct
35 Correct 180 ms 16868 KB Output is correct
36 Correct 292 ms 16996 KB Output is correct
37 Correct 270 ms 16996 KB Output is correct
38 Correct 241 ms 16868 KB Output is correct