답안 #52575

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52575 2018-06-26T07:37:29 Z baactree Pinball (JOI14_pinball) C++17
0 / 100
15 ms 19064 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int m, n;
int A[100005], B[100005], C[100005], D[100005];
ll inf = 0x3f3f3f3f3f3f3f3f;
vector<int> xidx;
int sz;
struct SGT {
	ll tree[300005 << 2];
	SGT() {
		memset(tree, 0x3f, sizeof(tree));
	}
	void update(int idx, ll val) {
		idx += sz;
		tree[idx] = val;
		idx /= 2;
		while (idx) {
			tree[idx] = min(tree[idx * 2], tree[idx * 2 + 1]);
			idx /= 2;
		}
	}
	ll query(int le, int ri) {
		le += sz;
		ri += sz;
		ll ret = inf;
		while (le <= ri) {
			if (le & 1)ret = min(ret, tree[le++]);
			if (!(ri & 1))ret = min(ret, tree[ri--]);
			le /= 2;
			ri /= 2;
		}
		return ret;
	}
};
int get_idx(int x) {
	return lower_bound(xidx.begin(), xidx.end(), x) - xidx.begin();
}
SGT lsgt, rsgt;
int main() {
	scanf("%d%d", &m, &n);
	xidx.push_back(1);
	xidx.push_back(n);
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d%d", &A[i], &B[i], &C[i], &D[i]);
		xidx.push_back(A[i]);
		xidx.push_back(B[i]);
		xidx.push_back(C[i]);
	}
	sort(xidx.begin(), xidx.end());
	xidx.erase(unique(xidx.begin(), xidx.end()), xidx.end());
	sz = 1;
	while (sz < xidx.size())sz *= 2;
	lsgt.update(0, 0);
	rsgt.update(xidx.size() - 1, 0);
	ll ans = inf;
	for (int i = 0; i < m; i++) {
		ll le = lsgt.query(get_idx(A[i]), get_idx(B[i]));
		lsgt.update(get_idx(C[i]), min(inf,le+D[i]));
		ll ri = rsgt.query(get_idx(A[i]), get_idx(B[i]));
		rsgt.update(get_idx(C[i]), min(inf,ri+D[i]));
		ans = min(ans, min(le + ri, inf) + D[i]);
	}
	printf("%lld\n", ans == inf ? -1 : ans);
	return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:53:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while (sz < xidx.size())sz *= 2;
         ~~~^~~~~~~~~~~~~
pinball.cpp:41: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:45: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 Incorrect 15 ms 19064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 19064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 19064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 19064 KB Output isn't correct
2 Halted 0 ms 0 KB -