Submission #595509

# Submission time Handle Problem Language Result Execution time Memory
595509 2022-07-13T19:23:18 Z Deepesson Uplifting Excursion (BOI22_vault) C++17
20 / 100
4240 ms 4364 KB
#include <bits/stdc++.h>
#define MAX 1000005
int maximo[MAX];
int bonus = MAX/2;
typedef std::pair<int,int> pii;
int main()
{
    long long N,M;
    std::cin>>N>>M;
    if(abs(M)>bonus){
        std::cout<<"impossible\n";
        return 0;
    }
    for(auto&x:maximo)x=-(1e6);
    maximo[bonus]=0;
    for(int i=-N;i<=N;++i){
        int c;
        std::cin>>c;
        if(!c)continue;
        int valor=abs(i);
        if(!valor){
            for(auto&x:maximo)x+=c;
            continue;
        }
        std::deque<pii> vals[valor];
        ///Da direita para a esquerda
        if(i>0){
            for(int j=0;j!=MAX-1;++j){
                int mod = j%valor;
                int kok = j/valor;
                int v = -(1e8);
                while(vals[mod].size()){
                    if(kok-vals[mod].front().second>c){
                        vals[mod].pop_front();
                        continue;
                    }
                    v=vals[mod].front().first+kok;
                    break;
                }
                while(vals[mod].size()&&vals[mod].back().first<maximo[j]-kok)vals[mod].pop_back();
                vals[mod].push_back({maximo[j]-kok,kok});
                maximo[j]=std::max(maximo[j],v);
            }
        }else if(i<0){
            for(int j=MAX-1;j!=-1;--j){
                int mod = j%valor;
                int kok = j/valor;
                int v = -(1e8);
                while(vals[mod].size()){
                    if(abs(kok-vals[mod].front().second)>c){
                        vals[mod].pop_front();
                        continue;
                    }
                    v=vals[mod].front().first-kok;
                    break;
                }
                while(vals[mod].size()&&vals[mod].back().first<maximo[j]+kok)vals[mod].pop_back();
                vals[mod].push_back({maximo[j]+kok,kok});
                maximo[j]=std::max(maximo[j],v);
            }
        }
    }
    ///como proceder caso x=0?
    if(maximo[M+bonus]<=0){
        std::cout<<"impossible\n";
        return 0;
    }
    std::cout<<maximo[M+bonus]<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 83 ms 4196 KB Output is correct
2 Correct 60 ms 4192 KB Output is correct
3 Correct 23 ms 4216 KB Output is correct
4 Correct 163 ms 4212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1882 ms 4248 KB Output is correct
7 Correct 849 ms 4244 KB Output is correct
8 Correct 1904 ms 4248 KB Output is correct
9 Correct 1880 ms 4248 KB Output is correct
10 Correct 39 ms 4180 KB Output is correct
11 Correct 94 ms 4244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 4196 KB Output is correct
2 Correct 60 ms 4192 KB Output is correct
3 Correct 23 ms 4216 KB Output is correct
4 Correct 163 ms 4212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1882 ms 4248 KB Output is correct
7 Correct 849 ms 4244 KB Output is correct
8 Correct 1904 ms 4248 KB Output is correct
9 Correct 1880 ms 4248 KB Output is correct
10 Correct 39 ms 4180 KB Output is correct
11 Correct 94 ms 4244 KB Output is correct
12 Correct 82 ms 4196 KB Output is correct
13 Correct 65 ms 4192 KB Output is correct
14 Correct 22 ms 4308 KB Output is correct
15 Correct 157 ms 4180 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1881 ms 4256 KB Output is correct
18 Correct 874 ms 4244 KB Output is correct
19 Correct 1829 ms 4248 KB Output is correct
20 Correct 1914 ms 4248 KB Output is correct
21 Correct 40 ms 4180 KB Output is correct
22 Correct 95 ms 4240 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 3769 ms 4356 KB Output is correct
25 Correct 1549 ms 4356 KB Output is correct
26 Correct 4240 ms 4360 KB Output is correct
27 Correct 3916 ms 4364 KB Output is correct
28 Correct 39 ms 4308 KB Output is correct
29 Correct 95 ms 4316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 4324 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 159 ms 4324 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 159 ms 4324 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 83 ms 4196 KB Output is correct
2 Correct 60 ms 4192 KB Output is correct
3 Correct 23 ms 4216 KB Output is correct
4 Correct 163 ms 4212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1882 ms 4248 KB Output is correct
7 Correct 849 ms 4244 KB Output is correct
8 Correct 1904 ms 4248 KB Output is correct
9 Correct 1880 ms 4248 KB Output is correct
10 Correct 39 ms 4180 KB Output is correct
11 Correct 94 ms 4244 KB Output is correct
12 Correct 159 ms 4324 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 159 ms 4324 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 83 ms 4196 KB Output is correct
2 Correct 60 ms 4192 KB Output is correct
3 Correct 23 ms 4216 KB Output is correct
4 Correct 163 ms 4212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1882 ms 4248 KB Output is correct
7 Correct 849 ms 4244 KB Output is correct
8 Correct 1904 ms 4248 KB Output is correct
9 Correct 1880 ms 4248 KB Output is correct
10 Correct 39 ms 4180 KB Output is correct
11 Correct 94 ms 4244 KB Output is correct
12 Correct 82 ms 4196 KB Output is correct
13 Correct 65 ms 4192 KB Output is correct
14 Correct 22 ms 4308 KB Output is correct
15 Correct 157 ms 4180 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1881 ms 4256 KB Output is correct
18 Correct 874 ms 4244 KB Output is correct
19 Correct 1829 ms 4248 KB Output is correct
20 Correct 1914 ms 4248 KB Output is correct
21 Correct 40 ms 4180 KB Output is correct
22 Correct 95 ms 4240 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 3769 ms 4356 KB Output is correct
25 Correct 1549 ms 4356 KB Output is correct
26 Correct 4240 ms 4360 KB Output is correct
27 Correct 3916 ms 4364 KB Output is correct
28 Correct 39 ms 4308 KB Output is correct
29 Correct 95 ms 4316 KB Output is correct
30 Correct 159 ms 4324 KB Output is correct
31 Incorrect 0 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 159 ms 4324 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 83 ms 4196 KB Output is correct
2 Correct 60 ms 4192 KB Output is correct
3 Correct 23 ms 4216 KB Output is correct
4 Correct 163 ms 4212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1882 ms 4248 KB Output is correct
7 Correct 849 ms 4244 KB Output is correct
8 Correct 1904 ms 4248 KB Output is correct
9 Correct 1880 ms 4248 KB Output is correct
10 Correct 39 ms 4180 KB Output is correct
11 Correct 94 ms 4244 KB Output is correct
12 Correct 82 ms 4196 KB Output is correct
13 Correct 65 ms 4192 KB Output is correct
14 Correct 22 ms 4308 KB Output is correct
15 Correct 157 ms 4180 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1881 ms 4256 KB Output is correct
18 Correct 874 ms 4244 KB Output is correct
19 Correct 1829 ms 4248 KB Output is correct
20 Correct 1914 ms 4248 KB Output is correct
21 Correct 40 ms 4180 KB Output is correct
22 Correct 95 ms 4240 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 3769 ms 4356 KB Output is correct
25 Correct 1549 ms 4356 KB Output is correct
26 Correct 4240 ms 4360 KB Output is correct
27 Correct 3916 ms 4364 KB Output is correct
28 Correct 39 ms 4308 KB Output is correct
29 Correct 95 ms 4316 KB Output is correct
30 Correct 159 ms 4324 KB Output is correct
31 Incorrect 0 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -