# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
153865 | 2019-09-17T05:45:41 Z | georgerapeanu | Pinball (JOI14_pinball) | C++11 | 815 ms | 26432 KB |
#include <cstdio> #include <map> #include <iostream> using namespace std; const int NMAX = 1e5; const int LEAFS = 3e5; const long long inf = 1e17; int n,k; int a[NMAX + 5]; int b[NMAX + 5]; int c[NMAX + 5]; int d[NMAX + 5]; map<int,int> to_norm; long long cost[NMAX + 5]; long long cost2[NMAX + 5]; long long aint[2 * LEAFS + 5]; void reset(){ for(int i = 1;i <= 2 * LEAFS;i++){ aint[i] = inf; } } void update(int pos,long long val){ pos += LEAFS; for(aint[pos] = min(aint[pos],val);pos > 1;(pos >>= 1)){ aint[pos >> 1] = min(aint[pos >> 1],val); } } long long query(int l,int r){ long long ans = inf; r++; for(l += LEAFS,r += LEAFS;l < r;(l >>= 1),(r >>= 1)){ if(l & 1)ans = min(ans,aint[l++]); if(r & 1)ans = min(ans,aint[--r]); } return ans; } int main(){ scanf("%d %d",&k,&n); for(int i = 1;i <= k;i++){ scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]); to_norm[a[i]] = 1; to_norm[b[i]] = 1; to_norm[c[i]] = 1; } to_norm[1] = 1; to_norm[n] = 1; int last = 0; for(auto &it:to_norm){ it.second = ++last; } reset(); update(1,0); for(int i = 1;i <= k;i++){ cost[i] = d[i] + query(to_norm[a[i]],to_norm[b[i]]); update(to_norm[c[i]],cost[i]); } reset(); update(to_norm[n],0); for(int i = 1;i <= k;i++){ cost2[i] = d[i] + query(to_norm[a[i]],to_norm[b[i]]); update(to_norm[c[i]],cost2[i]); } long long ans = inf; for(int i = 1;i <= k;i++){ ans = min(ans,cost[i] + cost2[i] - d[i]); } printf("%lld\n",(ans == inf ? -1:ans)); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5116 KB | Output is correct |
2 | Correct | 6 ms | 5112 KB | Output is correct |
3 | Correct | 8 ms | 4984 KB | Output is correct |
4 | Correct | 7 ms | 4984 KB | Output is correct |
5 | Correct | 7 ms | 5112 KB | Output is correct |
6 | Correct | 8 ms | 5112 KB | Output is correct |
7 | Correct | 7 ms | 5112 KB | Output is correct |
8 | Correct | 7 ms | 5112 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5116 KB | Output is correct |
2 | Correct | 6 ms | 5112 KB | Output is correct |
3 | Correct | 8 ms | 4984 KB | Output is correct |
4 | Correct | 7 ms | 4984 KB | Output is correct |
5 | Correct | 7 ms | 5112 KB | Output is correct |
6 | Correct | 8 ms | 5112 KB | Output is correct |
7 | Correct | 7 ms | 5112 KB | Output is correct |
8 | Correct | 7 ms | 5112 KB | Output is correct |
9 | Correct | 8 ms | 4980 KB | Output is correct |
10 | Correct | 8 ms | 4984 KB | Output is correct |
11 | Correct | 10 ms | 4988 KB | Output is correct |
12 | Correct | 7 ms | 5112 KB | Output is correct |
13 | Correct | 7 ms | 5112 KB | Output is correct |
14 | Correct | 7 ms | 5112 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5116 KB | Output is correct |
2 | Correct | 6 ms | 5112 KB | Output is correct |
3 | Correct | 8 ms | 4984 KB | Output is correct |
4 | Correct | 7 ms | 4984 KB | Output is correct |
5 | Correct | 7 ms | 5112 KB | Output is correct |
6 | Correct | 8 ms | 5112 KB | Output is correct |
7 | Correct | 7 ms | 5112 KB | Output is correct |
8 | Correct | 7 ms | 5112 KB | Output is correct |
9 | Correct | 8 ms | 4980 KB | Output is correct |
10 | Correct | 8 ms | 4984 KB | Output is correct |
11 | Correct | 10 ms | 4988 KB | Output is correct |
12 | Correct | 7 ms | 5112 KB | Output is correct |
13 | Correct | 7 ms | 5112 KB | Output is correct |
14 | Correct | 7 ms | 5112 KB | Output is correct |
15 | Correct | 6 ms | 4984 KB | Output is correct |
16 | Correct | 7 ms | 5112 KB | Output is correct |
17 | Correct | 9 ms | 5240 KB | Output is correct |
18 | Correct | 8 ms | 5112 KB | Output is correct |
19 | Correct | 9 ms | 5240 KB | Output is correct |
20 | Correct | 8 ms | 5112 KB | Output is correct |
21 | Correct | 7 ms | 5112 KB | Output is correct |
22 | Correct | 9 ms | 5240 KB | Output is correct |
23 | Correct | 8 ms | 5240 KB | Output is correct |
24 | Correct | 9 ms | 5240 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5116 KB | Output is correct |
2 | Correct | 6 ms | 5112 KB | Output is correct |
3 | Correct | 8 ms | 4984 KB | Output is correct |
4 | Correct | 7 ms | 4984 KB | Output is correct |
5 | Correct | 7 ms | 5112 KB | Output is correct |
6 | Correct | 8 ms | 5112 KB | Output is correct |
7 | Correct | 7 ms | 5112 KB | Output is correct |
8 | Correct | 7 ms | 5112 KB | Output is correct |
9 | Correct | 8 ms | 4980 KB | Output is correct |
10 | Correct | 8 ms | 4984 KB | Output is correct |
11 | Correct | 10 ms | 4988 KB | Output is correct |
12 | Correct | 7 ms | 5112 KB | Output is correct |
13 | Correct | 7 ms | 5112 KB | Output is correct |
14 | Correct | 7 ms | 5112 KB | Output is correct |
15 | Correct | 6 ms | 4984 KB | Output is correct |
16 | Correct | 7 ms | 5112 KB | Output is correct |
17 | Correct | 9 ms | 5240 KB | Output is correct |
18 | Correct | 8 ms | 5112 KB | Output is correct |
19 | Correct | 9 ms | 5240 KB | Output is correct |
20 | Correct | 8 ms | 5112 KB | Output is correct |
21 | Correct | 7 ms | 5112 KB | Output is correct |
22 | Correct | 9 ms | 5240 KB | Output is correct |
23 | Correct | 8 ms | 5240 KB | Output is correct |
24 | Correct | 9 ms | 5240 KB | Output is correct |
25 | Correct | 38 ms | 6392 KB | Output is correct |
26 | Correct | 112 ms | 9252 KB | Output is correct |
27 | Correct | 467 ms | 13132 KB | Output is correct |
28 | Correct | 174 ms | 9432 KB | Output is correct |
29 | Correct | 265 ms | 11916 KB | Output is correct |
30 | Correct | 317 ms | 10092 KB | Output is correct |
31 | Correct | 676 ms | 17408 KB | Output is correct |
32 | Correct | 572 ms | 15244 KB | Output is correct |
33 | Correct | 61 ms | 9080 KB | Output is correct |
34 | Correct | 323 ms | 15056 KB | Output is correct |
35 | Correct | 308 ms | 23672 KB | Output is correct |
36 | Correct | 815 ms | 24116 KB | Output is correct |
37 | Correct | 686 ms | 26432 KB | Output is correct |
38 | Correct | 624 ms | 26104 KB | Output is correct |