Submission #569488

# Submission time Handle Problem Language Result Execution time Memory
569488 2022-05-27T12:27:13 Z mat_v Pinball (JOI14_pinball) C++14
100 / 100
604 ms 31612 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n,duz;
int br = 0;
map<int,int> poj;
ll INF=1e8;

struct prep{
    int l,r,x;
    ll w;
}niz[100005];

ll dp[100005];
ll sejv[100005];

ll seg[4*300005];

void update(int node, int l, int r, int poz, ll val){
    if(l == r){
        seg[node] = val;
        return;
    }
    int mid = (l + r) / 2;
    if(poz <= mid)update(node*2,l,mid,poz,val);
    else update(node*2+1,mid+1,r,poz,val);
    seg[node] = min(seg[node * 2 + 1], seg[node * 2]);
}
ll kveri(int node, int l, int r, int levo, int desno){
    if(levo > r || l > desno)return INF;
    if(l >= levo && r <= desno)return seg[node];
    int mid = (l + r) / 2;
    return min(kveri(node*2,l,mid,levo,desno), kveri(node*2+1,mid+1,r,levo,desno));

}

void radi(){

//    ff(i,1,n){
//        dp[i] = INF;
//        if(niz[i].l == 1)dp[i] = niz[i].w;
//        else{
//            ff(j,1,i - 1){
//                if(niz[j].x >= niz[i].l && niz[j].x <= niz[i].r)dp[i] = min(dp[i], niz[i].w + dp[j]);
//            }
//        }
//    }

    update(1,1,duz,1,0);
    ff(i,2,duz)update(1,1,duz,i,INF);
    ff(i,1,n){
        dp[i] = kveri(1,1,duz,niz[i].l,niz[i].r) + niz[i].w;
        update(1,1,duz,niz[i].x,min(kveri(1,1,duz,niz[i].l,niz[i].r)+niz[i].w,kveri(1,1,duz,niz[i].x,niz[i].x)));

    }
}
void radi2(){
    ff(i,1,n){
        dp[i] = INF;
        if(niz[i].r == duz)dp[i] = niz[i].w;
        else{
            ff(j,1,i - 1){
                if(niz[j].x >= niz[i].l && niz[j].x <= niz[i].r)dp[i] = min(dp[i], niz[i].w + dp[j]);
            }
        }
    }
}

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    INF *= INF;
    cin >> n >> duz;
    vector<int> svi;
    ll sm = 0;
    ff(i,1,n){

        cin >> niz[i].l >> niz[i].r >> niz[i].x >> niz[i].w;
        svi.pb(niz[i].l);
        svi.pb(niz[i].r);
        svi.pb(niz[i].x);
         sm += niz[i].w;
    }
    svi.pb(1);
    svi.pb(duz);
    sort(svi.begin(),svi.end());
    int lst = 0;
    int br = 0;
    for(auto c:svi){
        if(c == lst)continue;
        br++;
        poj[c] = br;
        lst = c;
    }
    duz = poj[duz];
    ff(i,1,n)niz[i] = {poj[niz[i].l], poj[niz[i].r], poj[niz[i].x], niz[i].w};
    radi();
    ff(i,1,n)sejv[i] = dp[i];
//  radi2();
    ff(i,1,n){
        niz[i].l = duz-niz[i].l+1;
        niz[i].r = duz-niz[i].r+1;
        niz[i].x = duz-niz[i].x+1;
        swap(niz[i].r,niz[i].l);
    }
    radi();
    ll ans = INF;
    ff(i,1,n){
        ans = min(ans, dp[i] + sejv[i] - niz[i].w);
    }
    if(ans <= sm)cout << ans << "\n";
    else cout << -1 << "\n";

    return 0;
}

Compilation message

pinball.cpp: In function 'void radi()':
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
pinball.cpp:69:5: note: in expansion of macro 'ff'
   69 |     ff(i,2,duz)update(1,1,duz,i,INF);
      |     ^~
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
pinball.cpp:70:5: note: in expansion of macro 'ff'
   70 |     ff(i,1,n){
      |     ^~
pinball.cpp: In function 'void radi2()':
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
pinball.cpp:77:5: note: in expansion of macro 'ff'
   77 |     ff(i,1,n){
      |     ^~
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
pinball.cpp:81:13: note: in expansion of macro 'ff'
   81 |             ff(j,1,i - 1){
      |             ^~
pinball.cpp: In function 'int main()':
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
pinball.cpp:96:5: note: in expansion of macro 'ff'
   96 |     ff(i,1,n){
      |     ^~
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
pinball.cpp:116:5: note: in expansion of macro 'ff'
  116 |     ff(i,1,n)niz[i] = {poj[niz[i].l], poj[niz[i].r], poj[niz[i].x], niz[i].w};
      |     ^~
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
pinball.cpp:118:5: note: in expansion of macro 'ff'
  118 |     ff(i,1,n)sejv[i] = dp[i];
      |     ^~
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
pinball.cpp:120:5: note: in expansion of macro 'ff'
  120 |     ff(i,1,n){
      |     ^~
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
pinball.cpp:128:5: note: in expansion of macro 'ff'
  128 |     ff(i,1,n){
      |     ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 5 ms 596 KB Output is correct
20 Correct 3 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 3 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 3 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 5 ms 596 KB Output is correct
20 Correct 3 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 3 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 3 ms 596 KB Output is correct
25 Correct 34 ms 2184 KB Output is correct
26 Correct 104 ms 5148 KB Output is correct
27 Correct 385 ms 13228 KB Output is correct
28 Correct 204 ms 9316 KB Output is correct
29 Correct 251 ms 11124 KB Output is correct
30 Correct 316 ms 10560 KB Output is correct
31 Correct 550 ms 21252 KB Output is correct
32 Correct 462 ms 16988 KB Output is correct
33 Correct 69 ms 5744 KB Output is correct
34 Correct 238 ms 15916 KB Output is correct
35 Correct 399 ms 31512 KB Output is correct
36 Correct 604 ms 31532 KB Output is correct
37 Correct 481 ms 31612 KB Output is correct
38 Correct 432 ms 31528 KB Output is correct