Submission #778858

# Submission time Handle Problem Language Result Execution time Memory
778858 2023-07-10T21:21:44 Z new_acc Uplifting Excursion (BOI22_vault) C++14
50 / 100
428 ms 1876 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=300+10;
const int M=302*300;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e16;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=2027865967;
const int L=20;
int n;
ll t[N*2],l,doz[N*2][2];
int p1[M*2+10],p2[M*2+10];
void add(int val,ll il,bool xd){
    if(!il) return;
    bool rev=0;
    for(int i=0;i<=M*2;i++){
        p2[i]=-INFi;
    }
    if(val<0){
        for(int i=0;i<M;i++){
            swap(p1[i],p1[M*2-i]);
        }
        rev=1;
        val*=(-1);
    }
    for(int i=0;i<val;i++){
        deque<pair<int,int> >kol;
        for(int i2=0;i2*val+i<=M*2;i2++){
            int id=i2*val+i;
            int cval=p1[id];
            if(xd) cval-=i2;
            else cval+=i2;
            if(p1[id]!=-INFi){
                while(kol.size() and kol.back().fi<=cval){
                    kol.pop_back();
                }
                kol.push_back({cval,i2});
            }
            if(kol.size() and i2-kol.front().se==il+1){
                kol.pop_front();
            }
            if(kol.size()){
                p2[id]=max(p2[id],(xd?i2:-i2)+kol.front().fi);
            }
        }
    }
    if(rev){
        for(int i=0;i<M;i++){
            swap(p1[i],p1[M*2-i]);
            swap(p2[i],p2[M*2-i]);
        }
    }
    for(int i=0;i<=M*2;i++){
        p1[i]=max(p1[i],p2[i]);
    }
}
ll pl(int val){
    for(int i=0;i<=M*2;i++) p1[i]=-INFi;
    p1[M]=0;
    for(int i=0;i<=n*2;i++){
        add(i-n,doz[i][0],0);
        add(i-n,doz[i][1],1);
    }
    return p1[val+M];
}
void solve(){
    cin>>n>>l;
    ll sum=0;
    for(int i=-n;i<=n;i++){
        cin>>t[i+n];
        sum+=t[i+n]*(ll)i;
    }
    if(sum<=l){
        l*=(ll)(-1); 
        for(int i=0;i<n;i++){
            swap(t[i],t[n*2-i]);
        }
    }
    ll curr=0,res=0;
    for(int i=-n;i<=n;i++){
        if(i<=0){
            curr+=t[i+n]*(ll)i;
            doz[-i+n][0]+=t[i+n];
            res+=t[i+n];
            continue;
        }
        int id=i+n;
        ll r=l-curr;
        ll il=(r+i-1)/i;
        il=min(il,t[i+n]);
        curr+=il*(ll)i;
        res+=il;
        if(il==0){
            doz[i+n][1]+=t[i+n]; 
            continue;
        }
        if(il==t[i+n]){
            doz[-i+n][0]+=t[i+n];
        }else{
            doz[-i+n][0]+=il;
            doz[i+n][1]+=(t[i+n]-il);
        }
    }
    if(abs(l-curr)>300){
        cout<<"impossible\n";
        return;
    }
    ll ans=pl(l-curr);
    if(ans==-INFi) cout<<"impossible\n";
    else cout<<res+ans<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    int tt=1;
    while(tt--) solve();
}

Compilation message

vault.cpp: In function 'void solve()':
vault.cpp:96:13: warning: unused variable 'id' [-Wunused-variable]
   96 |         int id=i+n;
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1748 KB Output is correct
2 Correct 3 ms 1748 KB Output is correct
3 Correct 2 ms 1748 KB Output is correct
4 Correct 7 ms 1748 KB Output is correct
5 Incorrect 142 ms 1748 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1748 KB Output is correct
2 Correct 3 ms 1748 KB Output is correct
3 Correct 2 ms 1748 KB Output is correct
4 Correct 7 ms 1748 KB Output is correct
5 Incorrect 142 ms 1748 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1748 KB Output is correct
2 Correct 38 ms 1728 KB Output is correct
3 Correct 12 ms 1856 KB Output is correct
4 Correct 42 ms 1864 KB Output is correct
5 Correct 44 ms 1748 KB Output is correct
6 Correct 44 ms 1724 KB Output is correct
7 Correct 4 ms 1748 KB Output is correct
8 Correct 6 ms 1748 KB Output is correct
9 Correct 21 ms 1620 KB Output is correct
10 Correct 27 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1748 KB Output is correct
2 Correct 38 ms 1728 KB Output is correct
3 Correct 12 ms 1856 KB Output is correct
4 Correct 42 ms 1864 KB Output is correct
5 Correct 44 ms 1748 KB Output is correct
6 Correct 44 ms 1724 KB Output is correct
7 Correct 4 ms 1748 KB Output is correct
8 Correct 6 ms 1748 KB Output is correct
9 Correct 21 ms 1620 KB Output is correct
10 Correct 27 ms 1748 KB Output is correct
11 Correct 5 ms 1748 KB Output is correct
12 Correct 3 ms 1620 KB Output is correct
13 Correct 2 ms 1620 KB Output is correct
14 Correct 7 ms 1748 KB Output is correct
15 Correct 38 ms 1620 KB Output is correct
16 Correct 11 ms 1620 KB Output is correct
17 Correct 42 ms 1748 KB Output is correct
18 Correct 39 ms 1620 KB Output is correct
19 Correct 44 ms 1620 KB Output is correct
20 Correct 3 ms 1620 KB Output is correct
21 Correct 6 ms 1748 KB Output is correct
22 Correct 21 ms 1620 KB Output is correct
23 Correct 27 ms 1620 KB Output is correct
24 Correct 79 ms 1724 KB Output is correct
25 Correct 24 ms 1748 KB Output is correct
26 Correct 86 ms 1876 KB Output is correct
27 Correct 80 ms 1820 KB Output is correct
28 Correct 85 ms 1680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1748 KB Output is correct
2 Correct 38 ms 1728 KB Output is correct
3 Correct 12 ms 1856 KB Output is correct
4 Correct 42 ms 1864 KB Output is correct
5 Correct 44 ms 1748 KB Output is correct
6 Correct 44 ms 1724 KB Output is correct
7 Correct 4 ms 1748 KB Output is correct
8 Correct 6 ms 1748 KB Output is correct
9 Correct 21 ms 1620 KB Output is correct
10 Correct 27 ms 1748 KB Output is correct
11 Correct 7 ms 1748 KB Output is correct
12 Correct 37 ms 1724 KB Output is correct
13 Correct 11 ms 1748 KB Output is correct
14 Correct 42 ms 1748 KB Output is correct
15 Correct 38 ms 1724 KB Output is correct
16 Correct 43 ms 1748 KB Output is correct
17 Correct 3 ms 1748 KB Output is correct
18 Correct 6 ms 1748 KB Output is correct
19 Correct 21 ms 1620 KB Output is correct
20 Correct 27 ms 1748 KB Output is correct
21 Correct 3 ms 1748 KB Output is correct
22 Correct 6 ms 1748 KB Output is correct
23 Correct 62 ms 1728 KB Output is correct
24 Correct 26 ms 1748 KB Output is correct
25 Correct 62 ms 1748 KB Output is correct
26 Correct 68 ms 1748 KB Output is correct
27 Correct 77 ms 1728 KB Output is correct
28 Correct 46 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1748 KB Output is correct
2 Correct 3 ms 1748 KB Output is correct
3 Correct 2 ms 1748 KB Output is correct
4 Correct 7 ms 1748 KB Output is correct
5 Incorrect 142 ms 1748 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1748 KB Output is correct
2 Correct 38 ms 1728 KB Output is correct
3 Correct 12 ms 1856 KB Output is correct
4 Correct 42 ms 1864 KB Output is correct
5 Correct 44 ms 1748 KB Output is correct
6 Correct 44 ms 1724 KB Output is correct
7 Correct 4 ms 1748 KB Output is correct
8 Correct 6 ms 1748 KB Output is correct
9 Correct 21 ms 1620 KB Output is correct
10 Correct 27 ms 1748 KB Output is correct
11 Correct 7 ms 1748 KB Output is correct
12 Correct 37 ms 1724 KB Output is correct
13 Correct 11 ms 1748 KB Output is correct
14 Correct 42 ms 1748 KB Output is correct
15 Correct 38 ms 1724 KB Output is correct
16 Correct 43 ms 1748 KB Output is correct
17 Correct 3 ms 1748 KB Output is correct
18 Correct 6 ms 1748 KB Output is correct
19 Correct 21 ms 1620 KB Output is correct
20 Correct 27 ms 1748 KB Output is correct
21 Correct 3 ms 1748 KB Output is correct
22 Correct 6 ms 1748 KB Output is correct
23 Correct 62 ms 1728 KB Output is correct
24 Correct 26 ms 1748 KB Output is correct
25 Correct 62 ms 1748 KB Output is correct
26 Correct 68 ms 1748 KB Output is correct
27 Correct 77 ms 1728 KB Output is correct
28 Correct 46 ms 1620 KB Output is correct
29 Correct 7 ms 1620 KB Output is correct
30 Correct 47 ms 1728 KB Output is correct
31 Correct 11 ms 1748 KB Output is correct
32 Correct 42 ms 1620 KB Output is correct
33 Correct 38 ms 1620 KB Output is correct
34 Correct 44 ms 1620 KB Output is correct
35 Correct 3 ms 1620 KB Output is correct
36 Correct 6 ms 1748 KB Output is correct
37 Correct 21 ms 1752 KB Output is correct
38 Correct 27 ms 1748 KB Output is correct
39 Correct 3 ms 1656 KB Output is correct
40 Correct 6 ms 1744 KB Output is correct
41 Correct 65 ms 1728 KB Output is correct
42 Correct 26 ms 1620 KB Output is correct
43 Correct 62 ms 1748 KB Output is correct
44 Correct 81 ms 1748 KB Output is correct
45 Correct 73 ms 1728 KB Output is correct
46 Correct 45 ms 1728 KB Output is correct
47 Correct 3 ms 1748 KB Output is correct
48 Correct 6 ms 1748 KB Output is correct
49 Correct 122 ms 1748 KB Output is correct
50 Correct 50 ms 1748 KB Output is correct
51 Correct 133 ms 1748 KB Output is correct
52 Correct 131 ms 1748 KB Output is correct
53 Correct 153 ms 1748 KB Output is correct
54 Correct 108 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1748 KB Output is correct
2 Correct 3 ms 1748 KB Output is correct
3 Correct 2 ms 1748 KB Output is correct
4 Correct 7 ms 1748 KB Output is correct
5 Incorrect 142 ms 1748 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1748 KB Output is correct
2 Correct 38 ms 1728 KB Output is correct
3 Correct 12 ms 1856 KB Output is correct
4 Correct 42 ms 1864 KB Output is correct
5 Correct 44 ms 1748 KB Output is correct
6 Correct 44 ms 1724 KB Output is correct
7 Correct 4 ms 1748 KB Output is correct
8 Correct 6 ms 1748 KB Output is correct
9 Correct 21 ms 1620 KB Output is correct
10 Correct 27 ms 1748 KB Output is correct
11 Correct 7 ms 1748 KB Output is correct
12 Correct 37 ms 1724 KB Output is correct
13 Correct 11 ms 1748 KB Output is correct
14 Correct 42 ms 1748 KB Output is correct
15 Correct 38 ms 1724 KB Output is correct
16 Correct 43 ms 1748 KB Output is correct
17 Correct 3 ms 1748 KB Output is correct
18 Correct 6 ms 1748 KB Output is correct
19 Correct 21 ms 1620 KB Output is correct
20 Correct 27 ms 1748 KB Output is correct
21 Correct 3 ms 1748 KB Output is correct
22 Correct 6 ms 1748 KB Output is correct
23 Correct 62 ms 1728 KB Output is correct
24 Correct 26 ms 1748 KB Output is correct
25 Correct 62 ms 1748 KB Output is correct
26 Correct 68 ms 1748 KB Output is correct
27 Correct 77 ms 1728 KB Output is correct
28 Correct 46 ms 1620 KB Output is correct
29 Correct 7 ms 1620 KB Output is correct
30 Correct 47 ms 1728 KB Output is correct
31 Correct 11 ms 1748 KB Output is correct
32 Correct 42 ms 1620 KB Output is correct
33 Correct 38 ms 1620 KB Output is correct
34 Correct 44 ms 1620 KB Output is correct
35 Correct 3 ms 1620 KB Output is correct
36 Correct 6 ms 1748 KB Output is correct
37 Correct 21 ms 1752 KB Output is correct
38 Correct 27 ms 1748 KB Output is correct
39 Correct 3 ms 1656 KB Output is correct
40 Correct 6 ms 1744 KB Output is correct
41 Correct 65 ms 1728 KB Output is correct
42 Correct 26 ms 1620 KB Output is correct
43 Correct 62 ms 1748 KB Output is correct
44 Correct 81 ms 1748 KB Output is correct
45 Correct 73 ms 1728 KB Output is correct
46 Correct 45 ms 1728 KB Output is correct
47 Correct 3 ms 1748 KB Output is correct
48 Correct 6 ms 1748 KB Output is correct
49 Correct 122 ms 1748 KB Output is correct
50 Correct 50 ms 1748 KB Output is correct
51 Correct 133 ms 1748 KB Output is correct
52 Correct 131 ms 1748 KB Output is correct
53 Correct 153 ms 1748 KB Output is correct
54 Correct 108 ms 1620 KB Output is correct
55 Correct 7 ms 1620 KB Output is correct
56 Correct 37 ms 1748 KB Output is correct
57 Correct 11 ms 1748 KB Output is correct
58 Correct 41 ms 1620 KB Output is correct
59 Correct 42 ms 1620 KB Output is correct
60 Correct 46 ms 1724 KB Output is correct
61 Correct 4 ms 1620 KB Output is correct
62 Correct 6 ms 1748 KB Output is correct
63 Correct 26 ms 1620 KB Output is correct
64 Correct 27 ms 1748 KB Output is correct
65 Correct 3 ms 1748 KB Output is correct
66 Correct 6 ms 1744 KB Output is correct
67 Correct 62 ms 1736 KB Output is correct
68 Correct 26 ms 1728 KB Output is correct
69 Correct 63 ms 1728 KB Output is correct
70 Correct 80 ms 1620 KB Output is correct
71 Correct 81 ms 1740 KB Output is correct
72 Correct 46 ms 1724 KB Output is correct
73 Correct 3 ms 1748 KB Output is correct
74 Correct 6 ms 1748 KB Output is correct
75 Correct 120 ms 1748 KB Output is correct
76 Correct 50 ms 1620 KB Output is correct
77 Correct 129 ms 1728 KB Output is correct
78 Correct 141 ms 1748 KB Output is correct
79 Correct 142 ms 1748 KB Output is correct
80 Correct 105 ms 1620 KB Output is correct
81 Correct 428 ms 1748 KB Output is correct
82 Correct 164 ms 1728 KB Output is correct
83 Correct 370 ms 1748 KB Output is correct
84 Correct 408 ms 1732 KB Output is correct
85 Correct 4 ms 1748 KB Output is correct
86 Correct 8 ms 1748 KB Output is correct
87 Correct 321 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1748 KB Output is correct
2 Correct 3 ms 1748 KB Output is correct
3 Correct 2 ms 1748 KB Output is correct
4 Correct 7 ms 1748 KB Output is correct
5 Incorrect 142 ms 1748 KB Output isn't correct
6 Halted 0 ms 0 KB -