Submission #76971

# Submission time Handle Problem Language Result Execution time Memory
76971 2018-09-19T17:02:13 Z Vardanyan Pinball (JOI14_pinball) C++14
100 / 100
878 ms 137220 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1000*100+5;
const long long INF = 10000000000000005;
int A[N],B[N],C[N];
long long D[N];
long long dp1[N];
long long dp2[N];
struct node{
    node* l;
    node* r;
    long long val;
    node():l(NULL),r(NULL),val(INF){}
};
void update(node* v,int s,int e,int l,int r,long long val){
    if(l>r) return;
    if(s == l && e == r){
        v->val = val;
        return;
    }
    int m = (s+e)/2;
    if(v->l == NULL){
        v->l = new node();
        v->r = new node();
    }
    update(v->l,s,m,l,min(m,r),val);
    update(v->r,m+1,e,max(l,m+1),r,val);
    v->val = min(v->l->val,v->r->val);
}
long long query(node* v,int s,int e,int l,int r){
    if(l>r || v == NULL) return INF;
    if(s == l && e == r) return v->val;
    int m = (s+e)/2;
    return min(query(v->l,s,m,l,min(m,r)),query(v->r,m+1,e,max(l,m+1),r));
}
int main(){
    int m,n;
    scanf("%d%d",&m,&n);
    node* l = new node();
    node* r = new node();
    long long ans = INF;
    for(int i = 1;i<=m;i++){
        scanf("%d%d%d%lld",&A[i],&B[i],&C[i],&D[i]);
        long long cl;
        if(A[i] == 1){
            cl = D[i];
        }
        else{
            cl = query(l,1,n,A[i],B[i]);
            cl+=D[i];
        }
        long long x = query(l,1,n,C[i],C[i]);
        if(x>cl){
            update(l,1,n,C[i],C[i],cl);
        }
        long long cr;
        if(B[i] == n){
            cr = D[i];
        }
        else{
            cr = query(r,1,n,A[i],B[i]);
            cr+=D[i];
        }
        x = query(r,1,n,C[i],C[i]);
        if(x>cr){
            update(r,1,n,C[i],C[i],cr);
        }
        ans = min(ans,cl+cr-D[i]);
    }
    if(ans == INF) ans = -1;
    printf("%lld\n",ans);
    return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&m,&n);
     ~~~~~^~~~~~~~~~~~~~
pinball.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%lld",&A[i],&B[i],&C[i],&D[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 764 KB Output is correct
11 Correct 3 ms 900 KB Output is correct
12 Correct 2 ms 900 KB Output is correct
13 Correct 2 ms 900 KB Output is correct
14 Correct 3 ms 1068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 764 KB Output is correct
11 Correct 3 ms 900 KB Output is correct
12 Correct 2 ms 900 KB Output is correct
13 Correct 2 ms 900 KB Output is correct
14 Correct 3 ms 1068 KB Output is correct
15 Correct 3 ms 1068 KB Output is correct
16 Correct 2 ms 1068 KB Output is correct
17 Correct 7 ms 2120 KB Output is correct
18 Correct 6 ms 2120 KB Output is correct
19 Correct 6 ms 2120 KB Output is correct
20 Correct 7 ms 2120 KB Output is correct
21 Correct 3 ms 2120 KB Output is correct
22 Correct 4 ms 2120 KB Output is correct
23 Correct 5 ms 2120 KB Output is correct
24 Correct 5 ms 2120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 764 KB Output is correct
11 Correct 3 ms 900 KB Output is correct
12 Correct 2 ms 900 KB Output is correct
13 Correct 2 ms 900 KB Output is correct
14 Correct 3 ms 1068 KB Output is correct
15 Correct 3 ms 1068 KB Output is correct
16 Correct 2 ms 1068 KB Output is correct
17 Correct 7 ms 2120 KB Output is correct
18 Correct 6 ms 2120 KB Output is correct
19 Correct 6 ms 2120 KB Output is correct
20 Correct 7 ms 2120 KB Output is correct
21 Correct 3 ms 2120 KB Output is correct
22 Correct 4 ms 2120 KB Output is correct
23 Correct 5 ms 2120 KB Output is correct
24 Correct 5 ms 2120 KB Output is correct
25 Correct 37 ms 7028 KB Output is correct
26 Correct 136 ms 27232 KB Output is correct
27 Correct 453 ms 63244 KB Output is correct
28 Correct 349 ms 63244 KB Output is correct
29 Correct 285 ms 63244 KB Output is correct
30 Correct 687 ms 63244 KB Output is correct
31 Correct 878 ms 137220 KB Output is correct
32 Correct 844 ms 137220 KB Output is correct
33 Correct 48 ms 137220 KB Output is correct
34 Correct 119 ms 137220 KB Output is correct
35 Correct 302 ms 137220 KB Output is correct
36 Correct 525 ms 137220 KB Output is correct
37 Correct 259 ms 137220 KB Output is correct
38 Correct 257 ms 137220 KB Output is correct