Submission #607335

# Submission time Handle Problem Language Result Execution time Memory
607335 2022-07-26T15:26:17 Z duality Uplifting Excursion (BOI22_vault) C++17
45 / 100
191 ms 1108 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

LLI _A[601],*A = _A+300;
LLI _curr[601],*curr = _curr+300;
vpii poss;
int _dp[200001],*dp = _dp+100000;
int main() {
    int i;
    int M;
    LLI L;
    scanf("%d %lld",&M,&L);
    for (i = -M; i <= M; i++) scanf("%lld",&A[i]);

    LLI s1 = 0,s2 = 0,ans = 0;
    for (i = 1; i <= M; i++) s1 += i*A[i];
    for (i = -M; i <= -1; i++) s2 += i*A[i];
    if ((L > s1) || (L < s2)) {
        printf("impossible\n");
        return 0;
    }
    LLI s = 0;
    if (L >= s1+s2) {
        for (i = 0; i <= M; i++) curr[i] = A[i],s += i*A[i];
        for (i = -1; i >= -M; i--) curr[i] = min((s-L)/(-i),A[i]),s += i*curr[i];
    }
    else {
        for (i = 0; i >= -M; i--) curr[i] = A[i],s += i*A[i];
        for (i = 1; i <= M; i++) curr[i] = min((L-s)/i,A[i]),s += i*curr[i];
    }
    L -= s;
    for (i = -M; i <= M; i++) {
        ans += curr[i];
        if (i != 0) {
            int t = min(curr[i],(LLI) M);
            if (t > 0) {
                int k = 1;
                while (t > k) t -= k,poss.pb(mp(-k*i,-k)),k *= 2;
                poss.pb(mp(-t*i,-t));
            }
            t = min(A[i]-curr[i],(LLI) M);
            if (t > 0) {
                int k = 1;
                while (t > k) t -= k,poss.pb(mp(k*i,k)),k *= 2;
                poss.pb(mp(t*i,t));
            }
        }
    }
    int B = 100000;
    fill(dp-B,dp+B,-1e9),dp[0] = 0;
    for (auto [c,v]: poss) {
        if (c > 0) {
            for (i = B; i >= -B+c; i--) dp[i] = max(dp[i],dp[i-c]+v);
        }
        else {
            for (i = -B; i <= B+c; i++) dp[i] = max(dp[i],dp[i-c]+v);
        }
    }
    if (dp[L] < -1e8) printf("impossible\n");
    else printf("%lld\n",ans+dp[L]);

    return 0;
}

Compilation message

vault.cpp: In function 'int main()':
vault.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |     scanf("%d %lld",&M,&L);
      |     ~~~~~^~~~~~~~~~~~~~~~~
vault.cpp:67:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |     for (i = -M; i <= M; i++) scanf("%lld",&A[i]);
      |                               ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 7 ms 1092 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 82 ms 1088 KB Output is correct
7 Correct 34 ms 1096 KB Output is correct
8 Correct 80 ms 980 KB Output is correct
9 Correct 104 ms 1088 KB Output is correct
10 Correct 3 ms 980 KB Output is correct
11 Correct 5 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 7 ms 1092 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 82 ms 1088 KB Output is correct
7 Correct 34 ms 1096 KB Output is correct
8 Correct 80 ms 980 KB Output is correct
9 Correct 104 ms 1088 KB Output is correct
10 Correct 3 ms 980 KB Output is correct
11 Correct 5 ms 980 KB Output is correct
12 Correct 2 ms 1084 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
14 Correct 2 ms 1080 KB Output is correct
15 Correct 6 ms 1092 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 90 ms 1076 KB Output is correct
18 Correct 39 ms 980 KB Output is correct
19 Correct 80 ms 1076 KB Output is correct
20 Correct 98 ms 1088 KB Output is correct
21 Correct 4 ms 1080 KB Output is correct
22 Correct 6 ms 1080 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 191 ms 1108 KB Output is correct
25 Incorrect 71 ms 980 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1088 KB Output is correct
2 Correct 26 ms 980 KB Output is correct
3 Correct 7 ms 980 KB Output is correct
4 Correct 25 ms 980 KB Output is correct
5 Correct 29 ms 980 KB Output is correct
6 Correct 25 ms 980 KB Output is correct
7 Correct 5 ms 1080 KB Output is correct
8 Correct 6 ms 980 KB Output is correct
9 Correct 12 ms 1100 KB Output is correct
10 Correct 16 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1088 KB Output is correct
2 Correct 26 ms 980 KB Output is correct
3 Correct 7 ms 980 KB Output is correct
4 Correct 25 ms 980 KB Output is correct
5 Correct 29 ms 980 KB Output is correct
6 Correct 25 ms 980 KB Output is correct
7 Correct 5 ms 1080 KB Output is correct
8 Correct 6 ms 980 KB Output is correct
9 Correct 12 ms 1100 KB Output is correct
10 Correct 16 ms 980 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 5 ms 980 KB Output is correct
15 Correct 23 ms 980 KB Output is correct
16 Correct 7 ms 1088 KB Output is correct
17 Correct 25 ms 1092 KB Output is correct
18 Correct 33 ms 980 KB Output is correct
19 Correct 31 ms 1104 KB Output is correct
20 Correct 4 ms 980 KB Output is correct
21 Correct 4 ms 980 KB Output is correct
22 Correct 16 ms 1104 KB Output is correct
23 Correct 17 ms 980 KB Output is correct
24 Correct 47 ms 980 KB Output is correct
25 Correct 18 ms 980 KB Output is correct
26 Correct 51 ms 980 KB Output is correct
27 Correct 52 ms 1080 KB Output is correct
28 Correct 50 ms 1088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1088 KB Output is correct
2 Correct 26 ms 980 KB Output is correct
3 Correct 7 ms 980 KB Output is correct
4 Correct 25 ms 980 KB Output is correct
5 Correct 29 ms 980 KB Output is correct
6 Correct 25 ms 980 KB Output is correct
7 Correct 5 ms 1080 KB Output is correct
8 Correct 6 ms 980 KB Output is correct
9 Correct 12 ms 1100 KB Output is correct
10 Correct 16 ms 980 KB Output is correct
11 Correct 7 ms 1104 KB Output is correct
12 Correct 24 ms 980 KB Output is correct
13 Correct 7 ms 980 KB Output is correct
14 Correct 39 ms 980 KB Output is correct
15 Correct 32 ms 980 KB Output is correct
16 Correct 24 ms 1092 KB Output is correct
17 Correct 4 ms 980 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
19 Correct 15 ms 980 KB Output is correct
20 Correct 17 ms 1096 KB Output is correct
21 Correct 3 ms 980 KB Output is correct
22 Correct 10 ms 980 KB Output is correct
23 Correct 45 ms 980 KB Output is correct
24 Correct 20 ms 980 KB Output is correct
25 Correct 42 ms 1084 KB Output is correct
26 Correct 51 ms 1096 KB Output is correct
27 Correct 47 ms 1076 KB Output is correct
28 Correct 36 ms 1076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 7 ms 1092 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 82 ms 1088 KB Output is correct
7 Correct 34 ms 1096 KB Output is correct
8 Correct 80 ms 980 KB Output is correct
9 Correct 104 ms 1088 KB Output is correct
10 Correct 3 ms 980 KB Output is correct
11 Correct 5 ms 980 KB Output is correct
12 Correct 6 ms 1088 KB Output is correct
13 Correct 26 ms 980 KB Output is correct
14 Correct 7 ms 980 KB Output is correct
15 Correct 25 ms 980 KB Output is correct
16 Correct 29 ms 980 KB Output is correct
17 Correct 25 ms 980 KB Output is correct
18 Correct 5 ms 1080 KB Output is correct
19 Correct 6 ms 980 KB Output is correct
20 Correct 12 ms 1100 KB Output is correct
21 Correct 16 ms 980 KB Output is correct
22 Correct 2 ms 980 KB Output is correct
23 Correct 1 ms 980 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 5 ms 980 KB Output is correct
26 Correct 23 ms 980 KB Output is correct
27 Correct 7 ms 1088 KB Output is correct
28 Correct 25 ms 1092 KB Output is correct
29 Correct 33 ms 980 KB Output is correct
30 Correct 31 ms 1104 KB Output is correct
31 Correct 4 ms 980 KB Output is correct
32 Correct 4 ms 980 KB Output is correct
33 Correct 16 ms 1104 KB Output is correct
34 Correct 17 ms 980 KB Output is correct
35 Correct 47 ms 980 KB Output is correct
36 Correct 18 ms 980 KB Output is correct
37 Correct 51 ms 980 KB Output is correct
38 Correct 52 ms 1080 KB Output is correct
39 Correct 50 ms 1088 KB Output is correct
40 Correct 7 ms 1104 KB Output is correct
41 Correct 24 ms 980 KB Output is correct
42 Correct 7 ms 980 KB Output is correct
43 Correct 39 ms 980 KB Output is correct
44 Correct 32 ms 980 KB Output is correct
45 Correct 24 ms 1092 KB Output is correct
46 Correct 4 ms 980 KB Output is correct
47 Correct 4 ms 980 KB Output is correct
48 Correct 15 ms 980 KB Output is correct
49 Correct 17 ms 1096 KB Output is correct
50 Correct 3 ms 980 KB Output is correct
51 Correct 10 ms 980 KB Output is correct
52 Correct 45 ms 980 KB Output is correct
53 Correct 20 ms 980 KB Output is correct
54 Correct 42 ms 1084 KB Output is correct
55 Correct 51 ms 1096 KB Output is correct
56 Correct 47 ms 1076 KB Output is correct
57 Correct 36 ms 1076 KB Output is correct
58 Correct 3 ms 980 KB Output is correct
59 Correct 2 ms 1076 KB Output is correct
60 Correct 1 ms 980 KB Output is correct
61 Correct 5 ms 980 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 89 ms 1076 KB Output is correct
64 Correct 35 ms 980 KB Output is correct
65 Correct 89 ms 980 KB Output is correct
66 Correct 106 ms 980 KB Output is correct
67 Correct 3 ms 980 KB Output is correct
68 Correct 4 ms 980 KB Output is correct
69 Correct 23 ms 1092 KB Output is correct
70 Correct 7 ms 980 KB Output is correct
71 Correct 25 ms 1096 KB Output is correct
72 Correct 26 ms 980 KB Output is correct
73 Correct 23 ms 1096 KB Output is correct
74 Correct 5 ms 980 KB Output is correct
75 Correct 4 ms 980 KB Output is correct
76 Correct 16 ms 1096 KB Output is correct
77 Correct 18 ms 1100 KB Output is correct
78 Correct 45 ms 980 KB Output is correct
79 Correct 19 ms 1096 KB Output is correct
80 Correct 51 ms 1084 KB Output is correct
81 Correct 46 ms 980 KB Output is correct
82 Correct 47 ms 1080 KB Output is correct
83 Correct 49 ms 1076 KB Output is correct
84 Correct 20 ms 1076 KB Output is correct
85 Correct 48 ms 980 KB Output is correct
86 Correct 58 ms 980 KB Output is correct
87 Correct 50 ms 1080 KB Output is correct
88 Correct 36 ms 980 KB Output is correct
89 Correct 89 ms 1108 KB Output is correct
90 Correct 102 ms 1108 KB Output is correct
91 Correct 81 ms 1076 KB Output is correct
92 Correct 87 ms 1088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1088 KB Output is correct
2 Correct 26 ms 980 KB Output is correct
3 Correct 7 ms 980 KB Output is correct
4 Correct 25 ms 980 KB Output is correct
5 Correct 29 ms 980 KB Output is correct
6 Correct 25 ms 980 KB Output is correct
7 Correct 5 ms 1080 KB Output is correct
8 Correct 6 ms 980 KB Output is correct
9 Correct 12 ms 1100 KB Output is correct
10 Correct 16 ms 980 KB Output is correct
11 Correct 7 ms 1104 KB Output is correct
12 Correct 24 ms 980 KB Output is correct
13 Correct 7 ms 980 KB Output is correct
14 Correct 39 ms 980 KB Output is correct
15 Correct 32 ms 980 KB Output is correct
16 Correct 24 ms 1092 KB Output is correct
17 Correct 4 ms 980 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
19 Correct 15 ms 980 KB Output is correct
20 Correct 17 ms 1096 KB Output is correct
21 Correct 3 ms 980 KB Output is correct
22 Correct 10 ms 980 KB Output is correct
23 Correct 45 ms 980 KB Output is correct
24 Correct 20 ms 980 KB Output is correct
25 Correct 42 ms 1084 KB Output is correct
26 Correct 51 ms 1096 KB Output is correct
27 Correct 47 ms 1076 KB Output is correct
28 Correct 36 ms 1076 KB Output is correct
29 Correct 5 ms 980 KB Output is correct
30 Correct 26 ms 1092 KB Output is correct
31 Correct 7 ms 980 KB Output is correct
32 Correct 24 ms 1092 KB Output is correct
33 Correct 26 ms 980 KB Output is correct
34 Correct 23 ms 1096 KB Output is correct
35 Correct 3 ms 980 KB Output is correct
36 Correct 4 ms 980 KB Output is correct
37 Correct 13 ms 1092 KB Output is correct
38 Correct 21 ms 1092 KB Output is correct
39 Correct 3 ms 980 KB Output is correct
40 Correct 5 ms 980 KB Output is correct
41 Correct 48 ms 980 KB Output is correct
42 Correct 19 ms 980 KB Output is correct
43 Correct 44 ms 1092 KB Output is correct
44 Correct 53 ms 1092 KB Output is correct
45 Correct 46 ms 1084 KB Output is correct
46 Correct 37 ms 980 KB Output is correct
47 Correct 3 ms 1088 KB Output is correct
48 Correct 5 ms 980 KB Output is correct
49 Correct 103 ms 1108 KB Output is correct
50 Incorrect 43 ms 980 KB Output isn't correct
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 7 ms 1092 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 82 ms 1088 KB Output is correct
7 Correct 34 ms 1096 KB Output is correct
8 Correct 80 ms 980 KB Output is correct
9 Correct 104 ms 1088 KB Output is correct
10 Correct 3 ms 980 KB Output is correct
11 Correct 5 ms 980 KB Output is correct
12 Correct 2 ms 1084 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
14 Correct 2 ms 1080 KB Output is correct
15 Correct 6 ms 1092 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 90 ms 1076 KB Output is correct
18 Correct 39 ms 980 KB Output is correct
19 Correct 80 ms 1076 KB Output is correct
20 Correct 98 ms 1088 KB Output is correct
21 Correct 4 ms 1080 KB Output is correct
22 Correct 6 ms 1080 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 191 ms 1108 KB Output is correct
25 Incorrect 71 ms 980 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1088 KB Output is correct
2 Correct 26 ms 980 KB Output is correct
3 Correct 7 ms 980 KB Output is correct
4 Correct 25 ms 980 KB Output is correct
5 Correct 29 ms 980 KB Output is correct
6 Correct 25 ms 980 KB Output is correct
7 Correct 5 ms 1080 KB Output is correct
8 Correct 6 ms 980 KB Output is correct
9 Correct 12 ms 1100 KB Output is correct
10 Correct 16 ms 980 KB Output is correct
11 Correct 7 ms 1104 KB Output is correct
12 Correct 24 ms 980 KB Output is correct
13 Correct 7 ms 980 KB Output is correct
14 Correct 39 ms 980 KB Output is correct
15 Correct 32 ms 980 KB Output is correct
16 Correct 24 ms 1092 KB Output is correct
17 Correct 4 ms 980 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
19 Correct 15 ms 980 KB Output is correct
20 Correct 17 ms 1096 KB Output is correct
21 Correct 3 ms 980 KB Output is correct
22 Correct 10 ms 980 KB Output is correct
23 Correct 45 ms 980 KB Output is correct
24 Correct 20 ms 980 KB Output is correct
25 Correct 42 ms 1084 KB Output is correct
26 Correct 51 ms 1096 KB Output is correct
27 Correct 47 ms 1076 KB Output is correct
28 Correct 36 ms 1076 KB Output is correct
29 Correct 5 ms 980 KB Output is correct
30 Correct 26 ms 1092 KB Output is correct
31 Correct 7 ms 980 KB Output is correct
32 Correct 24 ms 1092 KB Output is correct
33 Correct 26 ms 980 KB Output is correct
34 Correct 23 ms 1096 KB Output is correct
35 Correct 3 ms 980 KB Output is correct
36 Correct 4 ms 980 KB Output is correct
37 Correct 13 ms 1092 KB Output is correct
38 Correct 21 ms 1092 KB Output is correct
39 Correct 3 ms 980 KB Output is correct
40 Correct 5 ms 980 KB Output is correct
41 Correct 48 ms 980 KB Output is correct
42 Correct 19 ms 980 KB Output is correct
43 Correct 44 ms 1092 KB Output is correct
44 Correct 53 ms 1092 KB Output is correct
45 Correct 46 ms 1084 KB Output is correct
46 Correct 37 ms 980 KB Output is correct
47 Correct 3 ms 1088 KB Output is correct
48 Correct 5 ms 980 KB Output is correct
49 Correct 103 ms 1108 KB Output is correct
50 Incorrect 43 ms 980 KB Output isn't correct
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 7 ms 1092 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 82 ms 1088 KB Output is correct
7 Correct 34 ms 1096 KB Output is correct
8 Correct 80 ms 980 KB Output is correct
9 Correct 104 ms 1088 KB Output is correct
10 Correct 3 ms 980 KB Output is correct
11 Correct 5 ms 980 KB Output is correct
12 Correct 2 ms 1084 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
14 Correct 2 ms 1080 KB Output is correct
15 Correct 6 ms 1092 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 90 ms 1076 KB Output is correct
18 Correct 39 ms 980 KB Output is correct
19 Correct 80 ms 1076 KB Output is correct
20 Correct 98 ms 1088 KB Output is correct
21 Correct 4 ms 1080 KB Output is correct
22 Correct 6 ms 1080 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 191 ms 1108 KB Output is correct
25 Incorrect 71 ms 980 KB Output isn't correct
26 Halted 0 ms 0 KB -