답안 #943680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
943680 2024-03-11T17:58:14 Z LucaIlie Uplifting Excursion (BOI22_vault) C++17
45 / 100
5000 ms 2140 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_M = 100;
const int MAX_S = MAX_M * MAX_M;
const int MIN_S = -MAX_S;
const long long INF = 1e18;
unordered_map<int, long long> taken, untaken;
unordered_map<int, long long> dpCrt, dpPrv;

int main() {
    int m;
    long long l, u = 0, t = 0;

    cin >> m >> l;
    for ( int i = -m; i <= m; i++ ) {
        cin >> untaken[i];
        u += untaken[i];
    }

    if ( l < 0 ) {
        for ( int i = 1; i <= m; i++ )
            swap( untaken[i], untaken[-i] );
        l = -l;
    }

    long long s = 0;
    for ( int i = -m; i <= 0; i++ ) {
        long long x = untaken[i];
        s += i * x;
        taken[i] += x;
        untaken[i] -= x;
        t += x;
        u -= x;
    }
    for ( int i = 1; i <= m; i++ ) {
        long long x = min( untaken[i], (l - s) / i );
        s += i * x;
        taken[i] += x;
        untaken[i] -= x;
        t += x;
        u -= x;
    }

    if ( s + m < l ) {
        for ( int i = -m; i < 0; i++ ) {
            long long x = min( taken[i], (l - s) / (-i) );
            s -= i * x;
            taken[i] -= x;
            untaken[i] += x;
            t -= x;
            u += x;
        }
    }

    /*cout << s << "\n";
    for ( int i = -m; i <= m; i++ )
        cout << taken[i] << " " << untaken[i] << "\n";*/

    for ( int s = MIN_S; s <= MAX_S; s++ )
        dpCrt[s] = -INF;
    dpCrt[0] = 0;
    for ( int i = -m; i <= -1; i++ ) {
        swap( dpCrt, dpPrv );

        for ( int s = MIN_S; s <= MAX_S; s++ )
            dpCrt[s] = -INF;

        for ( int x = 0; x <= m && x <= untaken[i]; x++ ) {
            for ( int s = MIN_S; s - i * x <= MAX_S; s++ )
                dpCrt[s] = max( dpCrt[s], dpPrv[s - i * x] + x );
        }
        for ( int x = 0; x <= m && x <= taken[i]; x++ ) {
            for ( int s = MIN_S - i * x; s <= MAX_S; s++ )
                dpCrt[s] = max( dpCrt[s], dpPrv[s + i * x] - x );
        }

        for ( int s = MIN_S; s <= MAX_S; s++ )
            dpCrt[s] = (dpCrt[s] <= -INF + m ? -INF : dpCrt[s] );

        /*for ( int s = MIN_S; s <= MAX_S; s++ )
            cout << dpCrt[s] << " ";
        cout << "\n";*/
    }
    for ( int i = 0; i <= m; i++ ) {
        swap( dpCrt, dpPrv );

        for ( int s = MIN_S; s <= MAX_S; s++ )
            dpCrt[s] = -INF;

        for ( int x = 0; x <= m && x <= untaken[i]; x++ ) {
            for ( int s = MIN_S + i * x; s <= MAX_S; s++ )
                dpCrt[s] = max( dpCrt[s], dpPrv[s - i * x] + x );
        }
        for ( int x = 0; x <= m && x <= taken[i]; x++ ) {
            for ( int s = MIN_S; s + i * x <= MAX_S; s++ )
                dpCrt[s] = max( dpCrt[s], dpPrv[s + i * x] - x );
        }

        for ( int s = MIN_S; s <= MAX_S; s++ )
            dpCrt[s] = (dpCrt[s] <= -INF + m ? -INF : dpCrt[s] );

        /*for ( int s = MIN_S; s <= MAX_S; s++ )
            cout << dpCrt[s] << " ";
        cout << "\n";*/
    }

    if ( l - s > MAX_S || dpCrt[l - s] == -INF )
        cout << "impossible\n";
    else
        cout << t + dpCrt[l - s] << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 1884 KB Output is correct
2 Correct 19 ms 1884 KB Output is correct
3 Correct 9 ms 1884 KB Output is correct
4 Correct 73 ms 2016 KB Output is correct
5 Correct 1594 ms 2008 KB Output is correct
6 Correct 1707 ms 2008 KB Output is correct
7 Correct 764 ms 2012 KB Output is correct
8 Correct 1633 ms 2136 KB Output is correct
9 Correct 2786 ms 2008 KB Output is correct
10 Correct 233 ms 1880 KB Output is correct
11 Correct 215 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 1884 KB Output is correct
2 Correct 19 ms 1884 KB Output is correct
3 Correct 9 ms 1884 KB Output is correct
4 Correct 73 ms 2016 KB Output is correct
5 Correct 1594 ms 2008 KB Output is correct
6 Correct 1707 ms 2008 KB Output is correct
7 Correct 764 ms 2012 KB Output is correct
8 Correct 1633 ms 2136 KB Output is correct
9 Correct 2786 ms 2008 KB Output is correct
10 Correct 233 ms 1880 KB Output is correct
11 Correct 215 ms 1884 KB Output is correct
12 Correct 17 ms 2140 KB Output is correct
13 Correct 20 ms 1884 KB Output is correct
14 Correct 10 ms 1884 KB Output is correct
15 Correct 72 ms 1884 KB Output is correct
16 Correct 1558 ms 2008 KB Output is correct
17 Correct 1663 ms 2024 KB Output is correct
18 Correct 759 ms 2008 KB Output is correct
19 Correct 1590 ms 2012 KB Output is correct
20 Correct 2792 ms 2012 KB Output is correct
21 Correct 232 ms 1880 KB Output is correct
22 Correct 222 ms 2132 KB Output is correct
23 Execution timed out 5012 ms 1880 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 2004 KB Output is correct
2 Correct 444 ms 2136 KB Output is correct
3 Correct 213 ms 2008 KB Output is correct
4 Correct 529 ms 2004 KB Output is correct
5 Correct 623 ms 2008 KB Output is correct
6 Correct 422 ms 2000 KB Output is correct
7 Correct 171 ms 2008 KB Output is correct
8 Correct 153 ms 2000 KB Output is correct
9 Correct 282 ms 2008 KB Output is correct
10 Correct 370 ms 2012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 2004 KB Output is correct
2 Correct 444 ms 2136 KB Output is correct
3 Correct 213 ms 2008 KB Output is correct
4 Correct 529 ms 2004 KB Output is correct
5 Correct 623 ms 2008 KB Output is correct
6 Correct 422 ms 2000 KB Output is correct
7 Correct 171 ms 2008 KB Output is correct
8 Correct 153 ms 2000 KB Output is correct
9 Correct 282 ms 2008 KB Output is correct
10 Correct 370 ms 2012 KB Output is correct
11 Correct 18 ms 2040 KB Output is correct
12 Correct 20 ms 2032 KB Output is correct
13 Correct 9 ms 1884 KB Output is correct
14 Correct 74 ms 2004 KB Output is correct
15 Correct 452 ms 2008 KB Output is correct
16 Correct 213 ms 2012 KB Output is correct
17 Correct 533 ms 1884 KB Output is correct
18 Correct 624 ms 2016 KB Output is correct
19 Correct 424 ms 2008 KB Output is correct
20 Correct 170 ms 1880 KB Output is correct
21 Correct 154 ms 2008 KB Output is correct
22 Correct 274 ms 2008 KB Output is correct
23 Correct 369 ms 2008 KB Output is correct
24 Correct 831 ms 2004 KB Output is correct
25 Correct 405 ms 1884 KB Output is correct
26 Correct 1081 ms 2012 KB Output is correct
27 Correct 789 ms 2136 KB Output is correct
28 Correct 842 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 2004 KB Output is correct
2 Correct 444 ms 2136 KB Output is correct
3 Correct 213 ms 2008 KB Output is correct
4 Correct 529 ms 2004 KB Output is correct
5 Correct 623 ms 2008 KB Output is correct
6 Correct 422 ms 2000 KB Output is correct
7 Correct 171 ms 2008 KB Output is correct
8 Correct 153 ms 2000 KB Output is correct
9 Correct 282 ms 2008 KB Output is correct
10 Correct 370 ms 2012 KB Output is correct
11 Correct 72 ms 1884 KB Output is correct
12 Correct 442 ms 2012 KB Output is correct
13 Correct 207 ms 1884 KB Output is correct
14 Correct 523 ms 2012 KB Output is correct
15 Correct 604 ms 2020 KB Output is correct
16 Correct 411 ms 2132 KB Output is correct
17 Correct 171 ms 1880 KB Output is correct
18 Correct 156 ms 2008 KB Output is correct
19 Correct 274 ms 2132 KB Output is correct
20 Correct 362 ms 1884 KB Output is correct
21 Correct 233 ms 1884 KB Output is correct
22 Correct 216 ms 2016 KB Output is correct
23 Correct 1058 ms 2012 KB Output is correct
24 Correct 615 ms 2016 KB Output is correct
25 Correct 1078 ms 2016 KB Output is correct
26 Correct 1531 ms 2128 KB Output is correct
27 Correct 1181 ms 2016 KB Output is correct
28 Correct 976 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 1884 KB Output is correct
2 Correct 19 ms 1884 KB Output is correct
3 Correct 9 ms 1884 KB Output is correct
4 Correct 73 ms 2016 KB Output is correct
5 Correct 1594 ms 2008 KB Output is correct
6 Correct 1707 ms 2008 KB Output is correct
7 Correct 764 ms 2012 KB Output is correct
8 Correct 1633 ms 2136 KB Output is correct
9 Correct 2786 ms 2008 KB Output is correct
10 Correct 233 ms 1880 KB Output is correct
11 Correct 215 ms 1884 KB Output is correct
12 Correct 71 ms 2004 KB Output is correct
13 Correct 444 ms 2136 KB Output is correct
14 Correct 213 ms 2008 KB Output is correct
15 Correct 529 ms 2004 KB Output is correct
16 Correct 623 ms 2008 KB Output is correct
17 Correct 422 ms 2000 KB Output is correct
18 Correct 171 ms 2008 KB Output is correct
19 Correct 153 ms 2000 KB Output is correct
20 Correct 282 ms 2008 KB Output is correct
21 Correct 370 ms 2012 KB Output is correct
22 Correct 18 ms 2040 KB Output is correct
23 Correct 20 ms 2032 KB Output is correct
24 Correct 9 ms 1884 KB Output is correct
25 Correct 74 ms 2004 KB Output is correct
26 Correct 452 ms 2008 KB Output is correct
27 Correct 213 ms 2012 KB Output is correct
28 Correct 533 ms 1884 KB Output is correct
29 Correct 624 ms 2016 KB Output is correct
30 Correct 424 ms 2008 KB Output is correct
31 Correct 170 ms 1880 KB Output is correct
32 Correct 154 ms 2008 KB Output is correct
33 Correct 274 ms 2008 KB Output is correct
34 Correct 369 ms 2008 KB Output is correct
35 Correct 831 ms 2004 KB Output is correct
36 Correct 405 ms 1884 KB Output is correct
37 Correct 1081 ms 2012 KB Output is correct
38 Correct 789 ms 2136 KB Output is correct
39 Correct 842 ms 2132 KB Output is correct
40 Correct 72 ms 1884 KB Output is correct
41 Correct 442 ms 2012 KB Output is correct
42 Correct 207 ms 1884 KB Output is correct
43 Correct 523 ms 2012 KB Output is correct
44 Correct 604 ms 2020 KB Output is correct
45 Correct 411 ms 2132 KB Output is correct
46 Correct 171 ms 1880 KB Output is correct
47 Correct 156 ms 2008 KB Output is correct
48 Correct 274 ms 2132 KB Output is correct
49 Correct 362 ms 1884 KB Output is correct
50 Correct 233 ms 1884 KB Output is correct
51 Correct 216 ms 2016 KB Output is correct
52 Correct 1058 ms 2012 KB Output is correct
53 Correct 615 ms 2016 KB Output is correct
54 Correct 1078 ms 2016 KB Output is correct
55 Correct 1531 ms 2128 KB Output is correct
56 Correct 1181 ms 2016 KB Output is correct
57 Correct 976 ms 2028 KB Output is correct
58 Correct 17 ms 1880 KB Output is correct
59 Correct 19 ms 1884 KB Output is correct
60 Correct 9 ms 1884 KB Output is correct
61 Correct 71 ms 1880 KB Output is correct
62 Correct 1556 ms 2036 KB Output is correct
63 Correct 1666 ms 2012 KB Output is correct
64 Correct 756 ms 2008 KB Output is correct
65 Correct 1589 ms 2020 KB Output is correct
66 Correct 2788 ms 2020 KB Output is correct
67 Correct 230 ms 1884 KB Output is correct
68 Correct 218 ms 2036 KB Output is correct
69 Correct 446 ms 2004 KB Output is correct
70 Correct 204 ms 2012 KB Output is correct
71 Correct 513 ms 1880 KB Output is correct
72 Correct 609 ms 2132 KB Output is correct
73 Correct 411 ms 1880 KB Output is correct
74 Correct 170 ms 2008 KB Output is correct
75 Correct 152 ms 1880 KB Output is correct
76 Correct 271 ms 1884 KB Output is correct
77 Correct 362 ms 2016 KB Output is correct
78 Correct 800 ms 2012 KB Output is correct
79 Correct 400 ms 2004 KB Output is correct
80 Correct 1071 ms 2008 KB Output is correct
81 Correct 787 ms 2024 KB Output is correct
82 Correct 837 ms 2008 KB Output is correct
83 Correct 1057 ms 1880 KB Output is correct
84 Correct 605 ms 2016 KB Output is correct
85 Correct 1071 ms 2128 KB Output is correct
86 Correct 1520 ms 2132 KB Output is correct
87 Correct 1187 ms 2032 KB Output is correct
88 Correct 992 ms 2012 KB Output is correct
89 Correct 1934 ms 2128 KB Output is correct
90 Correct 2857 ms 2008 KB Output is correct
91 Correct 1981 ms 2032 KB Output is correct
92 Correct 2144 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 2004 KB Output is correct
2 Correct 444 ms 2136 KB Output is correct
3 Correct 213 ms 2008 KB Output is correct
4 Correct 529 ms 2004 KB Output is correct
5 Correct 623 ms 2008 KB Output is correct
6 Correct 422 ms 2000 KB Output is correct
7 Correct 171 ms 2008 KB Output is correct
8 Correct 153 ms 2000 KB Output is correct
9 Correct 282 ms 2008 KB Output is correct
10 Correct 370 ms 2012 KB Output is correct
11 Correct 72 ms 1884 KB Output is correct
12 Correct 442 ms 2012 KB Output is correct
13 Correct 207 ms 1884 KB Output is correct
14 Correct 523 ms 2012 KB Output is correct
15 Correct 604 ms 2020 KB Output is correct
16 Correct 411 ms 2132 KB Output is correct
17 Correct 171 ms 1880 KB Output is correct
18 Correct 156 ms 2008 KB Output is correct
19 Correct 274 ms 2132 KB Output is correct
20 Correct 362 ms 1884 KB Output is correct
21 Correct 233 ms 1884 KB Output is correct
22 Correct 216 ms 2016 KB Output is correct
23 Correct 1058 ms 2012 KB Output is correct
24 Correct 615 ms 2016 KB Output is correct
25 Correct 1078 ms 2016 KB Output is correct
26 Correct 1531 ms 2128 KB Output is correct
27 Correct 1181 ms 2016 KB Output is correct
28 Correct 976 ms 2028 KB Output is correct
29 Correct 74 ms 2004 KB Output is correct
30 Correct 453 ms 2012 KB Output is correct
31 Correct 202 ms 2016 KB Output is correct
32 Correct 515 ms 2012 KB Output is correct
33 Correct 606 ms 2012 KB Output is correct
34 Correct 410 ms 2008 KB Output is correct
35 Correct 169 ms 2128 KB Output is correct
36 Correct 158 ms 1884 KB Output is correct
37 Correct 273 ms 2008 KB Output is correct
38 Correct 363 ms 2012 KB Output is correct
39 Correct 232 ms 2008 KB Output is correct
40 Correct 217 ms 1880 KB Output is correct
41 Correct 1053 ms 2016 KB Output is correct
42 Correct 621 ms 2128 KB Output is correct
43 Correct 1070 ms 2020 KB Output is correct
44 Correct 1522 ms 2012 KB Output is correct
45 Correct 1172 ms 2132 KB Output is correct
46 Correct 976 ms 2012 KB Output is correct
47 Correct 466 ms 1884 KB Output is correct
48 Correct 443 ms 1880 KB Output is correct
49 Correct 3648 ms 2132 KB Output is correct
50 Correct 1731 ms 2024 KB Output is correct
51 Correct 3975 ms 2016 KB Output is correct
52 Execution timed out 5064 ms 1884 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 1884 KB Output is correct
2 Correct 19 ms 1884 KB Output is correct
3 Correct 9 ms 1884 KB Output is correct
4 Correct 73 ms 2016 KB Output is correct
5 Correct 1594 ms 2008 KB Output is correct
6 Correct 1707 ms 2008 KB Output is correct
7 Correct 764 ms 2012 KB Output is correct
8 Correct 1633 ms 2136 KB Output is correct
9 Correct 2786 ms 2008 KB Output is correct
10 Correct 233 ms 1880 KB Output is correct
11 Correct 215 ms 1884 KB Output is correct
12 Correct 17 ms 2140 KB Output is correct
13 Correct 20 ms 1884 KB Output is correct
14 Correct 10 ms 1884 KB Output is correct
15 Correct 72 ms 1884 KB Output is correct
16 Correct 1558 ms 2008 KB Output is correct
17 Correct 1663 ms 2024 KB Output is correct
18 Correct 759 ms 2008 KB Output is correct
19 Correct 1590 ms 2012 KB Output is correct
20 Correct 2792 ms 2012 KB Output is correct
21 Correct 232 ms 1880 KB Output is correct
22 Correct 222 ms 2132 KB Output is correct
23 Execution timed out 5012 ms 1880 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 2004 KB Output is correct
2 Correct 444 ms 2136 KB Output is correct
3 Correct 213 ms 2008 KB Output is correct
4 Correct 529 ms 2004 KB Output is correct
5 Correct 623 ms 2008 KB Output is correct
6 Correct 422 ms 2000 KB Output is correct
7 Correct 171 ms 2008 KB Output is correct
8 Correct 153 ms 2000 KB Output is correct
9 Correct 282 ms 2008 KB Output is correct
10 Correct 370 ms 2012 KB Output is correct
11 Correct 72 ms 1884 KB Output is correct
12 Correct 442 ms 2012 KB Output is correct
13 Correct 207 ms 1884 KB Output is correct
14 Correct 523 ms 2012 KB Output is correct
15 Correct 604 ms 2020 KB Output is correct
16 Correct 411 ms 2132 KB Output is correct
17 Correct 171 ms 1880 KB Output is correct
18 Correct 156 ms 2008 KB Output is correct
19 Correct 274 ms 2132 KB Output is correct
20 Correct 362 ms 1884 KB Output is correct
21 Correct 233 ms 1884 KB Output is correct
22 Correct 216 ms 2016 KB Output is correct
23 Correct 1058 ms 2012 KB Output is correct
24 Correct 615 ms 2016 KB Output is correct
25 Correct 1078 ms 2016 KB Output is correct
26 Correct 1531 ms 2128 KB Output is correct
27 Correct 1181 ms 2016 KB Output is correct
28 Correct 976 ms 2028 KB Output is correct
29 Correct 74 ms 2004 KB Output is correct
30 Correct 453 ms 2012 KB Output is correct
31 Correct 202 ms 2016 KB Output is correct
32 Correct 515 ms 2012 KB Output is correct
33 Correct 606 ms 2012 KB Output is correct
34 Correct 410 ms 2008 KB Output is correct
35 Correct 169 ms 2128 KB Output is correct
36 Correct 158 ms 1884 KB Output is correct
37 Correct 273 ms 2008 KB Output is correct
38 Correct 363 ms 2012 KB Output is correct
39 Correct 232 ms 2008 KB Output is correct
40 Correct 217 ms 1880 KB Output is correct
41 Correct 1053 ms 2016 KB Output is correct
42 Correct 621 ms 2128 KB Output is correct
43 Correct 1070 ms 2020 KB Output is correct
44 Correct 1522 ms 2012 KB Output is correct
45 Correct 1172 ms 2132 KB Output is correct
46 Correct 976 ms 2012 KB Output is correct
47 Correct 466 ms 1884 KB Output is correct
48 Correct 443 ms 1880 KB Output is correct
49 Correct 3648 ms 2132 KB Output is correct
50 Correct 1731 ms 2024 KB Output is correct
51 Correct 3975 ms 2016 KB Output is correct
52 Execution timed out 5064 ms 1884 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 1884 KB Output is correct
2 Correct 19 ms 1884 KB Output is correct
3 Correct 9 ms 1884 KB Output is correct
4 Correct 73 ms 2016 KB Output is correct
5 Correct 1594 ms 2008 KB Output is correct
6 Correct 1707 ms 2008 KB Output is correct
7 Correct 764 ms 2012 KB Output is correct
8 Correct 1633 ms 2136 KB Output is correct
9 Correct 2786 ms 2008 KB Output is correct
10 Correct 233 ms 1880 KB Output is correct
11 Correct 215 ms 1884 KB Output is correct
12 Correct 17 ms 2140 KB Output is correct
13 Correct 20 ms 1884 KB Output is correct
14 Correct 10 ms 1884 KB Output is correct
15 Correct 72 ms 1884 KB Output is correct
16 Correct 1558 ms 2008 KB Output is correct
17 Correct 1663 ms 2024 KB Output is correct
18 Correct 759 ms 2008 KB Output is correct
19 Correct 1590 ms 2012 KB Output is correct
20 Correct 2792 ms 2012 KB Output is correct
21 Correct 232 ms 1880 KB Output is correct
22 Correct 222 ms 2132 KB Output is correct
23 Execution timed out 5012 ms 1880 KB Time limit exceeded
24 Halted 0 ms 0 KB -