# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153863 | 2019-09-17T05:43:51 Z | georgerapeanu | Pinball (JOI14_pinball) | C++11 | 1000 ms | 38728 KB |
#include <cstdio> #include <map> #include <iostream> using namespace std; const int NMAX = 1e5; const int LEAFS = 4e5; 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[4 * LEAFS + 5]; void reset(){ for(int i = 1;i <= 4 * 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[d[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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 13048 KB | Output is correct |
2 | Correct | 14 ms | 12792 KB | Output is correct |
3 | Correct | 14 ms | 12792 KB | Output is correct |
4 | Correct | 14 ms | 12920 KB | Output is correct |
5 | Correct | 14 ms | 12792 KB | Output is correct |
6 | Correct | 14 ms | 13048 KB | Output is correct |
7 | Correct | 14 ms | 12792 KB | Output is correct |
8 | Correct | 17 ms | 12920 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 13048 KB | Output is correct |
2 | Correct | 14 ms | 12792 KB | Output is correct |
3 | Correct | 14 ms | 12792 KB | Output is correct |
4 | Correct | 14 ms | 12920 KB | Output is correct |
5 | Correct | 14 ms | 12792 KB | Output is correct |
6 | Correct | 14 ms | 13048 KB | Output is correct |
7 | Correct | 14 ms | 12792 KB | Output is correct |
8 | Correct | 17 ms | 12920 KB | Output is correct |
9 | Correct | 15 ms | 13048 KB | Output is correct |
10 | Correct | 14 ms | 12920 KB | Output is correct |
11 | Correct | 15 ms | 12968 KB | Output is correct |
12 | Correct | 15 ms | 12920 KB | Output is correct |
13 | Correct | 14 ms | 12920 KB | Output is correct |
14 | Correct | 15 ms | 12920 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 13048 KB | Output is correct |
2 | Correct | 14 ms | 12792 KB | Output is correct |
3 | Correct | 14 ms | 12792 KB | Output is correct |
4 | Correct | 14 ms | 12920 KB | Output is correct |
5 | Correct | 14 ms | 12792 KB | Output is correct |
6 | Correct | 14 ms | 13048 KB | Output is correct |
7 | Correct | 14 ms | 12792 KB | Output is correct |
8 | Correct | 17 ms | 12920 KB | Output is correct |
9 | Correct | 15 ms | 13048 KB | Output is correct |
10 | Correct | 14 ms | 12920 KB | Output is correct |
11 | Correct | 15 ms | 12968 KB | Output is correct |
12 | Correct | 15 ms | 12920 KB | Output is correct |
13 | Correct | 14 ms | 12920 KB | Output is correct |
14 | Correct | 15 ms | 12920 KB | Output is correct |
15 | Correct | 15 ms | 13048 KB | Output is correct |
16 | Correct | 15 ms | 12920 KB | Output is correct |
17 | Correct | 17 ms | 13048 KB | Output is correct |
18 | Correct | 16 ms | 13048 KB | Output is correct |
19 | Correct | 17 ms | 13176 KB | Output is correct |
20 | Correct | 17 ms | 13048 KB | Output is correct |
21 | Correct | 15 ms | 12920 KB | Output is correct |
22 | Correct | 17 ms | 13176 KB | Output is correct |
23 | Correct | 16 ms | 13048 KB | Output is correct |
24 | Correct | 17 ms | 13176 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 13048 KB | Output is correct |
2 | Correct | 14 ms | 12792 KB | Output is correct |
3 | Correct | 14 ms | 12792 KB | Output is correct |
4 | Correct | 14 ms | 12920 KB | Output is correct |
5 | Correct | 14 ms | 12792 KB | Output is correct |
6 | Correct | 14 ms | 13048 KB | Output is correct |
7 | Correct | 14 ms | 12792 KB | Output is correct |
8 | Correct | 17 ms | 12920 KB | Output is correct |
9 | Correct | 15 ms | 13048 KB | Output is correct |
10 | Correct | 14 ms | 12920 KB | Output is correct |
11 | Correct | 15 ms | 12968 KB | Output is correct |
12 | Correct | 15 ms | 12920 KB | Output is correct |
13 | Correct | 14 ms | 12920 KB | Output is correct |
14 | Correct | 15 ms | 12920 KB | Output is correct |
15 | Correct | 15 ms | 13048 KB | Output is correct |
16 | Correct | 15 ms | 12920 KB | Output is correct |
17 | Correct | 17 ms | 13048 KB | Output is correct |
18 | Correct | 16 ms | 13048 KB | Output is correct |
19 | Correct | 17 ms | 13176 KB | Output is correct |
20 | Correct | 17 ms | 13048 KB | Output is correct |
21 | Correct | 15 ms | 12920 KB | Output is correct |
22 | Correct | 17 ms | 13176 KB | Output is correct |
23 | Correct | 16 ms | 13048 KB | Output is correct |
24 | Correct | 17 ms | 13176 KB | Output is correct |
25 | Correct | 54 ms | 14712 KB | Output is correct |
26 | Correct | 179 ms | 18260 KB | Output is correct |
27 | Correct | 526 ms | 25788 KB | Output is correct |
28 | Correct | 329 ms | 24568 KB | Output is correct |
29 | Correct | 357 ms | 23020 KB | Output is correct |
30 | Correct | 560 ms | 25560 KB | Output is correct |
31 | Correct | 932 ms | 32468 KB | Output is correct |
32 | Correct | 882 ms | 30208 KB | Output is correct |
33 | Correct | 90 ms | 17852 KB | Output is correct |
34 | Correct | 509 ms | 25852 KB | Output is correct |
35 | Correct | 479 ms | 38728 KB | Output is correct |
36 | Execution timed out | 1079 ms | 38704 KB | Time limit exceeded |
37 | Halted | 0 ms | 0 KB | - |