답안 #287474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287474 2020-08-31T17:17:45 Z Namnamseo Pinball (JOI14_pinball) C++17
100 / 100
274 ms 23368 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n, w;

const ll inf = 1ll<<60;
struct seg {
	static const int M=524288;
	ll tree[M<<1];
	void init(){ for(ll& x:tree) x=inf; }
	ll rmin(int l, int r){
		l+=M; r+=M; ll ret=inf;
		while(l<=r){
			if(l%2==1) ret=min(ret, tree[l++]);
			if(r%2==0) ret=min(ret, tree[r--]);
			l>>=1; r>>=1;
		}
		return ret;
	}
	void put(int p, ll val){ for(p+=M;p;p>>=1) tree[p]=min(tree[p], val); }
} lt, rt;

typedef tuple<int,int,int,int> t4;
t4 d[100010];

int C[300010], Cn;
int f(int x){ return lower_bound(C, C+Cn, x)-C; }

int main()
{
	read(n, w);
	for(int i=1; i<=n; ++i){
		int a,b,c,d; read(a,b,c,d); ::d[i]=t4{a,b,c,d};
		C[Cn++]=a; C[Cn++]=b; C[Cn++]=c;
	}
	C[Cn++]=1; C[Cn++]=w;
	sort(C, C+Cn); Cn=unique(C, C+Cn)-C;
	lt.init(); rt.init(); lt.put(f(1), 0); rt.put(f(w), 0);
	ll ans=inf;
	for(int i=1; i<=n; ++i){
		int a,b,c,d; tie(a,b,c,d)=::d[i];
		a=f(a); b=f(b); c=f(c);
		ans=min(ans, lt.rmin(a, b) + rt.rmin(a, b) + d);
		lt.put(c, lt.rmin(a, b) + d);
		rt.put(c, rt.rmin(a, b) + d);
	}
	if(ans==inf)ans=-1;
	printf("%lld\n", ans);
	return 0;
}

Compilation message

pinball.cpp: In function 'void read(int&)':
pinball.cpp:6:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    6 | void read(int& x){ scanf("%d",&x); }
      |                    ~~~~~^~~~~~~~~
pinball.cpp: In function 'void read(ll&)':
pinball.cpp:7:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    7 | void read(ll& x){ scanf("%lld",&x); }
      |                   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16768 KB Output is correct
2 Correct 10 ms 16768 KB Output is correct
3 Correct 11 ms 16768 KB Output is correct
4 Correct 10 ms 16768 KB Output is correct
5 Correct 11 ms 16768 KB Output is correct
6 Correct 11 ms 16768 KB Output is correct
7 Correct 10 ms 16768 KB Output is correct
8 Correct 10 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16768 KB Output is correct
2 Correct 10 ms 16768 KB Output is correct
3 Correct 11 ms 16768 KB Output is correct
4 Correct 10 ms 16768 KB Output is correct
5 Correct 11 ms 16768 KB Output is correct
6 Correct 11 ms 16768 KB Output is correct
7 Correct 10 ms 16768 KB Output is correct
8 Correct 10 ms 16768 KB Output is correct
9 Correct 10 ms 16768 KB Output is correct
10 Correct 13 ms 16768 KB Output is correct
11 Correct 13 ms 16812 KB Output is correct
12 Correct 10 ms 16800 KB Output is correct
13 Correct 11 ms 16768 KB Output is correct
14 Correct 10 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16768 KB Output is correct
2 Correct 10 ms 16768 KB Output is correct
3 Correct 11 ms 16768 KB Output is correct
4 Correct 10 ms 16768 KB Output is correct
5 Correct 11 ms 16768 KB Output is correct
6 Correct 11 ms 16768 KB Output is correct
7 Correct 10 ms 16768 KB Output is correct
8 Correct 10 ms 16768 KB Output is correct
9 Correct 10 ms 16768 KB Output is correct
10 Correct 13 ms 16768 KB Output is correct
11 Correct 13 ms 16812 KB Output is correct
12 Correct 10 ms 16800 KB Output is correct
13 Correct 11 ms 16768 KB Output is correct
14 Correct 10 ms 16768 KB Output is correct
15 Correct 10 ms 16768 KB Output is correct
16 Correct 11 ms 16768 KB Output is correct
17 Correct 12 ms 16768 KB Output is correct
18 Correct 11 ms 16768 KB Output is correct
19 Correct 12 ms 16768 KB Output is correct
20 Correct 13 ms 16768 KB Output is correct
21 Correct 11 ms 16768 KB Output is correct
22 Correct 12 ms 16768 KB Output is correct
23 Correct 11 ms 16768 KB Output is correct
24 Correct 11 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16768 KB Output is correct
2 Correct 10 ms 16768 KB Output is correct
3 Correct 11 ms 16768 KB Output is correct
4 Correct 10 ms 16768 KB Output is correct
5 Correct 11 ms 16768 KB Output is correct
6 Correct 11 ms 16768 KB Output is correct
7 Correct 10 ms 16768 KB Output is correct
8 Correct 10 ms 16768 KB Output is correct
9 Correct 10 ms 16768 KB Output is correct
10 Correct 13 ms 16768 KB Output is correct
11 Correct 13 ms 16812 KB Output is correct
12 Correct 10 ms 16800 KB Output is correct
13 Correct 11 ms 16768 KB Output is correct
14 Correct 10 ms 16768 KB Output is correct
15 Correct 10 ms 16768 KB Output is correct
16 Correct 11 ms 16768 KB Output is correct
17 Correct 12 ms 16768 KB Output is correct
18 Correct 11 ms 16768 KB Output is correct
19 Correct 12 ms 16768 KB Output is correct
20 Correct 13 ms 16768 KB Output is correct
21 Correct 11 ms 16768 KB Output is correct
22 Correct 12 ms 16768 KB Output is correct
23 Correct 11 ms 16768 KB Output is correct
24 Correct 11 ms 16768 KB Output is correct
25 Correct 29 ms 17272 KB Output is correct
26 Correct 67 ms 18364 KB Output is correct
27 Correct 177 ms 21300 KB Output is correct
28 Correct 163 ms 23288 KB Output is correct
29 Correct 117 ms 20088 KB Output is correct
30 Correct 197 ms 23288 KB Output is correct
31 Correct 246 ms 23288 KB Output is correct
32 Correct 230 ms 23288 KB Output is correct
33 Correct 34 ms 17920 KB Output is correct
34 Correct 123 ms 19960 KB Output is correct
35 Correct 142 ms 23288 KB Output is correct
36 Correct 274 ms 23368 KB Output is correct
37 Correct 200 ms 23288 KB Output is correct
38 Correct 188 ms 23288 KB Output is correct