Submission #77747

# Submission time Handle Problem Language Result Execution time Memory
77747 2018-09-30T07:20:25 Z nxteru Pinball (JOI14_pinball) C++14
100 / 100
795 ms 81228 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,m,k,x[100005],y[100005],z[100005],d[100005],seg[2][1<<20],ans=INF;
vector<ll>cm;
map<ll,ll>pr;
void ini(void){
    for(int i=0;i<1<<20;i++){
        seg[0][i]=INF;
        seg[1][i]=INF;
    }
}
void up(int s,int a,ll b){
    a+=(1<<19)-1;
    seg[s][a]=min(seg[s][a],b);
    while(a>0){
        a=(a-1)/2;
        seg[s][a]=min(seg[s][a*2+1],seg[s][a*2+2]);
    }
}
ll que(int s,int a,int b,int l,int r,int o){
    if(r<a||b<l)return INF;
    if(a<=l&&r<=b)return seg[s][o];
    return min(que(s,a,b,l,(l+r-1)/2,o*2+1),que(s,a,b,(l+r+1)/2,r,o*2+2));
}
int main(void){
    scanf("%lld%lld",&n,&m);
    cm.PB(1);
    cm.PB(m);
    for(int i=0;i<n;i++){
        scanf("%lld%lld%lld%lld",x+i,y+i,z+i,d+i);
        cm.PB(x[i]);
        cm.PB(y[i]);
        cm.PB(z[i]);
    }
    sort(cm.begin(),cm.end());
    cm.erase(unique(cm.begin(),cm.end()),cm.end());
    k=cm.size();
    for(int i=0;i<k;i++)pr[cm[i]]=i;
    for(int i=0;i<n;i++){
        x[i]=pr[x[i]];
        y[i]=pr[y[i]];
        z[i]=pr[z[i]];
    }
    m=pr[m];
    ini();
    up(0,0,0);
    up(1,m,0);
    for(int i=0;i<n;i++){
        ans=min(ans,que(0,x[i],y[i],0,(1<<19)-1,0)+que(1,x[i],y[i],0,(1<<19)-1,0)+d[i]);
        up(0,z[i],que(0,x[i],y[i],0,(1<<19)-1,0)+d[i]);
        up(1,z[i],que(1,x[i],y[i],0,(1<<19)-1,0)+d[i]);
    }
    if(ans==INF)ans=-1;
    printf("%lld\n",ans);
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~~~~
pinball.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld%lld",x+i,y+i,z+i,d+i);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16760 KB Output is correct
2 Correct 20 ms 16896 KB Output is correct
3 Correct 16 ms 16896 KB Output is correct
4 Correct 15 ms 16896 KB Output is correct
5 Correct 19 ms 16920 KB Output is correct
6 Correct 15 ms 16960 KB Output is correct
7 Correct 15 ms 16976 KB Output is correct
8 Correct 16 ms 16976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16760 KB Output is correct
2 Correct 20 ms 16896 KB Output is correct
3 Correct 16 ms 16896 KB Output is correct
4 Correct 15 ms 16896 KB Output is correct
5 Correct 19 ms 16920 KB Output is correct
6 Correct 15 ms 16960 KB Output is correct
7 Correct 15 ms 16976 KB Output is correct
8 Correct 16 ms 16976 KB Output is correct
9 Correct 19 ms 17140 KB Output is correct
10 Correct 17 ms 17192 KB Output is correct
11 Correct 17 ms 17216 KB Output is correct
12 Correct 16 ms 17248 KB Output is correct
13 Correct 17 ms 17264 KB Output is correct
14 Correct 15 ms 17272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16760 KB Output is correct
2 Correct 20 ms 16896 KB Output is correct
3 Correct 16 ms 16896 KB Output is correct
4 Correct 15 ms 16896 KB Output is correct
5 Correct 19 ms 16920 KB Output is correct
6 Correct 15 ms 16960 KB Output is correct
7 Correct 15 ms 16976 KB Output is correct
8 Correct 16 ms 16976 KB Output is correct
9 Correct 19 ms 17140 KB Output is correct
10 Correct 17 ms 17192 KB Output is correct
11 Correct 17 ms 17216 KB Output is correct
12 Correct 16 ms 17248 KB Output is correct
13 Correct 17 ms 17264 KB Output is correct
14 Correct 15 ms 17272 KB Output is correct
15 Correct 16 ms 17280 KB Output is correct
16 Correct 18 ms 17412 KB Output is correct
17 Correct 18 ms 17472 KB Output is correct
18 Correct 20 ms 17512 KB Output is correct
19 Correct 18 ms 17680 KB Output is correct
20 Correct 18 ms 17680 KB Output is correct
21 Correct 17 ms 17684 KB Output is correct
22 Correct 19 ms 17776 KB Output is correct
23 Correct 18 ms 17820 KB Output is correct
24 Correct 20 ms 18004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16760 KB Output is correct
2 Correct 20 ms 16896 KB Output is correct
3 Correct 16 ms 16896 KB Output is correct
4 Correct 15 ms 16896 KB Output is correct
5 Correct 19 ms 16920 KB Output is correct
6 Correct 15 ms 16960 KB Output is correct
7 Correct 15 ms 16976 KB Output is correct
8 Correct 16 ms 16976 KB Output is correct
9 Correct 19 ms 17140 KB Output is correct
10 Correct 17 ms 17192 KB Output is correct
11 Correct 17 ms 17216 KB Output is correct
12 Correct 16 ms 17248 KB Output is correct
13 Correct 17 ms 17264 KB Output is correct
14 Correct 15 ms 17272 KB Output is correct
15 Correct 16 ms 17280 KB Output is correct
16 Correct 18 ms 17412 KB Output is correct
17 Correct 18 ms 17472 KB Output is correct
18 Correct 20 ms 17512 KB Output is correct
19 Correct 18 ms 17680 KB Output is correct
20 Correct 18 ms 17680 KB Output is correct
21 Correct 17 ms 17684 KB Output is correct
22 Correct 19 ms 17776 KB Output is correct
23 Correct 18 ms 17820 KB Output is correct
24 Correct 20 ms 18004 KB Output is correct
25 Correct 61 ms 19576 KB Output is correct
26 Correct 132 ms 23696 KB Output is correct
27 Correct 382 ms 31620 KB Output is correct
28 Correct 252 ms 31620 KB Output is correct
29 Correct 265 ms 35632 KB Output is correct
30 Correct 365 ms 37680 KB Output is correct
31 Correct 597 ms 50908 KB Output is correct
32 Correct 568 ms 51796 KB Output is correct
33 Correct 87 ms 51796 KB Output is correct
34 Correct 336 ms 53600 KB Output is correct
35 Correct 468 ms 69560 KB Output is correct
36 Correct 795 ms 73568 KB Output is correct
37 Correct 622 ms 77356 KB Output is correct
38 Correct 605 ms 81228 KB Output is correct