답안 #25240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25240 2017-06-21T04:05:20 Z 김현수(#1059) Pinball (JOI14_pinball) C++14
100 / 100
316 ms 31724 KB
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const ll inf = 1e18;

ll n, m;

vector<ll> cp;
vector<tuple<ll,ll,ll,ll> > a;

struct segtree {
	ll val[1234567], lim;
	void init () {
		for(lim=1; lim<=cp.size(); lim<<=1);
		for(ll i=2*lim; --i; ) val[i] = inf;
	}
	void upd (ll P, ll V) {
		P += lim;
		while(P) {
			val[P] = min(val[P], V);
			P >>= 1;
		}
	}
	ll get (ll S, ll E) {
		ll ret = inf;
		S += lim; E += lim;
		while(S<=E) {
			if(S%2==1) {ret = min(val[S], ret); S++;}
			if(E%2==0) {ret = min(val[E], ret); E--;}
			S >>= 1; E >>= 1;
		}
		return ret;
	}
} l, r;

ll cpr (ll X) {
	return lower_bound(cp.begin(), cp.end(), X) - cp.begin();
}

int main()
{
	scanf("%lld%lld",&n,&m);
	for(ll i=1;i<=n;i++) {
		ll A, B, C, D;
		scanf("%lld%lld%lld%lld",&A,&B,&C,&D);
		a.pb(make_tuple(A,B,C,D));
		cp.pb(A); cp.pb(B); cp.pb(C);
	}
	cp.pb(1); cp.pb(m);

	sort(cp.begin(), cp.end());
	cp.erase(unique(cp.begin(), cp.end()), cp.end());

	l.init(); l.upd(0, 0);
	r.init(); r.upd(cp.size()-1, 0);

	ll ans = inf;
	for(auto &T : a) {
		ll A, B, C, D; tie(A, B, C, D) = T;
		A = cpr(A); B = cpr(B); C = cpr(C);
		ll X = l.get(A, B), Y = r.get(A, B);
		ans = min(ans, X + Y + D);
		l.upd(C, X+D); r.upd(C, Y+D);
	}
	printf("%lld\n", (ans == inf ? -1 : ans));
}

Compilation message

pinball.cpp: In member function 'void segtree::init()':
pinball.cpp:15:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(lim=1; lim<=cp.size(); lim<<=1);
                 ^
pinball.cpp: In function 'int main()':
pinball.cpp:43:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld",&n,&m);
                         ^
pinball.cpp:46:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld%lld",&A,&B,&C,&D);
                                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 21312 KB Output is correct
2 Correct 0 ms 21312 KB Output is correct
3 Correct 0 ms 21312 KB Output is correct
4 Correct 0 ms 21312 KB Output is correct
5 Correct 0 ms 21312 KB Output is correct
6 Correct 0 ms 21312 KB Output is correct
7 Correct 0 ms 21312 KB Output is correct
8 Correct 0 ms 21312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 21312 KB Output is correct
2 Correct 0 ms 21312 KB Output is correct
3 Correct 0 ms 21312 KB Output is correct
4 Correct 0 ms 21312 KB Output is correct
5 Correct 0 ms 21312 KB Output is correct
6 Correct 0 ms 21312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 21312 KB Output is correct
2 Correct 0 ms 21312 KB Output is correct
3 Correct 0 ms 21472 KB Output is correct
4 Correct 0 ms 21472 KB Output is correct
5 Correct 0 ms 21472 KB Output is correct
6 Correct 0 ms 21472 KB Output is correct
7 Correct 0 ms 21312 KB Output is correct
8 Correct 0 ms 21472 KB Output is correct
9 Correct 0 ms 21472 KB Output is correct
10 Correct 0 ms 21472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 22508 KB Output is correct
2 Correct 49 ms 24044 KB Output is correct
3 Correct 183 ms 29676 KB Output is correct
4 Correct 143 ms 31724 KB Output is correct
5 Correct 103 ms 26604 KB Output is correct
6 Correct 153 ms 31724 KB Output is correct
7 Correct 269 ms 31724 KB Output is correct
8 Correct 239 ms 31724 KB Output is correct
9 Correct 19 ms 23532 KB Output is correct
10 Correct 99 ms 26604 KB Output is correct
11 Correct 186 ms 31724 KB Output is correct
12 Correct 316 ms 31724 KB Output is correct
13 Correct 179 ms 31724 KB Output is correct
14 Correct 206 ms 31724 KB Output is correct