답안 #944094

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944094 2024-03-12T08:26:51 Z LucaIlie Uplifting Excursion (BOI22_vault) C++17
45 / 100
5000 ms 2036 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_M = 300;
int MAX_S;
int MIN_S;
const long long INF = 1e18;
int m;
unordered_map<int, long long> taken, untaken;
unordered_map<int, long long> dpCrt, dpPrv;

void add( int x, int k ) {
    swap( dpCrt, dpPrv );

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

    /*if ( x > 0 ) {
        for ( int r = 0; r < x; r++ ) {
            deque<pair<int, int>> d;
            for ( int i = 0, s = MIN_S + r; s <= MAX_S; i++, s += x ) {
                if ( !d.empty() && i - d.front().second > k )
                    d.pop_front();
                while ( !d.empty() && dpPrv[s] - i >= dpPrv[d.back().first] - d.back().second )
                    d.pop_back();
                d.push_back( { s, i } );
                dpCrt[s] = dpPrv[d.front().first] + i - d.front().second;
            }
        }
    } else {
        x = -x;
        for ( int r = 0; r < x; r++ ) {
            deque<pair<int, int>> d;
            for ( int i = 0, s = MAX_S - r; s >= MAX_S; i++, s -= x ) {
                if ( !d.empty() && i - d.front().second > k )
                    d.pop_front();
                while ( !d.empty() && dpPrv[s] - i >= dpPrv[d.back().first] - d.back().second )
                    d.pop_back();
                d.push_back( { s, i } );
                dpCrt[s] = dpPrv[d.front().first] + i - d.front().second;
            }
        }
    }*/

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

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

void substract( int x, int k ) {
    swap( dpCrt, dpPrv );

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

    /*if ( x < 0 ) {
        x = -x;
        for ( int r = 0; r < x; r++ ) {
            deque<pair<int, int>> d;
            for ( int i = 0, s = MIN_S + r; s <= MAX_S; i++, s += x ) {
                if ( !d.empty() && i - d.front().second > k )
                    d.pop_front();
                while ( !d.empty() && dpPrv[s] + i >= dpPrv[d.back().first] + d.back().second )
                    d.pop_back();
                d.push_back( { s, i } );
                dpCrt[s] = dpPrv[d.front().first] - i + d.front().second;
            }
        }
    } else {
        for ( int r = 0; r < x; r++ ) {
            deque<pair<int, int>> d;
            for ( int i = 0, s = MAX_S - r; s >= MAX_S; i++, s -= x ) {
                if ( !d.empty() && i - d.front().second > k )
                    d.pop_front();
                while ( !d.empty() && dpPrv[s] + i >= dpPrv[d.back().first] + d.back().second )
                    d.pop_back();
                d.push_back( { s, i } );
                dpCrt[s] = dpPrv[d.front().first] - i + d.front().second;
            }
        }
    }*/


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

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

void afis() {
    for ( int s = MIN_S; s <= MAX_S; s++ ) {
        cout << dpCrt[s] << " ";
    }
    cout << "\n";
}

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

    cin >> m >> l;
    MIN_S = -m * m;
    MAX_S = m * m;
    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 << i << " " << 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 <= m; i++ ) {
        add( i, min( (long long)m, untaken[i] ) );
        substract( i, min( (long long)m, taken[i] ) );
    }


    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 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 502 ms 816 KB Output is correct
6 Correct 521 ms 604 KB Output is correct
7 Correct 262 ms 816 KB Output is correct
8 Correct 509 ms 604 KB Output is correct
9 Correct 850 ms 816 KB Output is correct
10 Correct 100 ms 944 KB Output is correct
11 Correct 94 ms 812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 502 ms 816 KB Output is correct
6 Correct 521 ms 604 KB Output is correct
7 Correct 262 ms 816 KB Output is correct
8 Correct 509 ms 604 KB Output is correct
9 Correct 850 ms 816 KB Output is correct
10 Correct 100 ms 944 KB Output is correct
11 Correct 94 ms 812 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 506 ms 812 KB Output is correct
17 Correct 523 ms 600 KB Output is correct
18 Correct 263 ms 820 KB Output is correct
19 Correct 505 ms 604 KB Output is correct
20 Correct 859 ms 824 KB Output is correct
21 Correct 99 ms 600 KB Output is correct
22 Correct 94 ms 816 KB Output is correct
23 Execution timed out 5057 ms 1884 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 58 ms 348 KB Output is correct
3 Correct 27 ms 344 KB Output is correct
4 Correct 62 ms 568 KB Output is correct
5 Correct 67 ms 344 KB Output is correct
6 Correct 49 ms 344 KB Output is correct
7 Correct 24 ms 596 KB Output is correct
8 Correct 22 ms 600 KB Output is correct
9 Correct 36 ms 604 KB Output is correct
10 Correct 45 ms 568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 58 ms 348 KB Output is correct
3 Correct 27 ms 344 KB Output is correct
4 Correct 62 ms 568 KB Output is correct
5 Correct 67 ms 344 KB Output is correct
6 Correct 49 ms 344 KB Output is correct
7 Correct 24 ms 596 KB Output is correct
8 Correct 22 ms 600 KB Output is correct
9 Correct 36 ms 604 KB Output is correct
10 Correct 45 ms 568 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 52 ms 572 KB Output is correct
16 Correct 28 ms 348 KB Output is correct
17 Correct 60 ms 564 KB Output is correct
18 Correct 73 ms 344 KB Output is correct
19 Correct 49 ms 348 KB Output is correct
20 Correct 23 ms 348 KB Output is correct
21 Correct 25 ms 348 KB Output is correct
22 Correct 35 ms 564 KB Output is correct
23 Correct 45 ms 344 KB Output is correct
24 Correct 92 ms 596 KB Output is correct
25 Correct 50 ms 348 KB Output is correct
26 Correct 120 ms 568 KB Output is correct
27 Correct 88 ms 568 KB Output is correct
28 Correct 92 ms 564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 58 ms 348 KB Output is correct
3 Correct 27 ms 344 KB Output is correct
4 Correct 62 ms 568 KB Output is correct
5 Correct 67 ms 344 KB Output is correct
6 Correct 49 ms 344 KB Output is correct
7 Correct 24 ms 596 KB Output is correct
8 Correct 22 ms 600 KB Output is correct
9 Correct 36 ms 604 KB Output is correct
10 Correct 45 ms 568 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 52 ms 572 KB Output is correct
13 Correct 28 ms 344 KB Output is correct
14 Correct 59 ms 564 KB Output is correct
15 Correct 67 ms 348 KB Output is correct
16 Correct 49 ms 568 KB Output is correct
17 Correct 24 ms 568 KB Output is correct
18 Correct 22 ms 348 KB Output is correct
19 Correct 35 ms 348 KB Output is correct
20 Correct 48 ms 436 KB Output is correct
21 Correct 97 ms 604 KB Output is correct
22 Correct 94 ms 600 KB Output is correct
23 Correct 352 ms 816 KB Output is correct
24 Correct 209 ms 812 KB Output is correct
25 Correct 344 ms 604 KB Output is correct
26 Correct 473 ms 820 KB Output is correct
27 Correct 378 ms 612 KB Output is correct
28 Correct 323 ms 816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 502 ms 816 KB Output is correct
6 Correct 521 ms 604 KB Output is correct
7 Correct 262 ms 816 KB Output is correct
8 Correct 509 ms 604 KB Output is correct
9 Correct 850 ms 816 KB Output is correct
10 Correct 100 ms 944 KB Output is correct
11 Correct 94 ms 812 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 58 ms 348 KB Output is correct
14 Correct 27 ms 344 KB Output is correct
15 Correct 62 ms 568 KB Output is correct
16 Correct 67 ms 344 KB Output is correct
17 Correct 49 ms 344 KB Output is correct
18 Correct 24 ms 596 KB Output is correct
19 Correct 22 ms 600 KB Output is correct
20 Correct 36 ms 604 KB Output is correct
21 Correct 45 ms 568 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 52 ms 572 KB Output is correct
27 Correct 28 ms 348 KB Output is correct
28 Correct 60 ms 564 KB Output is correct
29 Correct 73 ms 344 KB Output is correct
30 Correct 49 ms 348 KB Output is correct
31 Correct 23 ms 348 KB Output is correct
32 Correct 25 ms 348 KB Output is correct
33 Correct 35 ms 564 KB Output is correct
34 Correct 45 ms 344 KB Output is correct
35 Correct 92 ms 596 KB Output is correct
36 Correct 50 ms 348 KB Output is correct
37 Correct 120 ms 568 KB Output is correct
38 Correct 88 ms 568 KB Output is correct
39 Correct 92 ms 564 KB Output is correct
40 Correct 2 ms 344 KB Output is correct
41 Correct 52 ms 572 KB Output is correct
42 Correct 28 ms 344 KB Output is correct
43 Correct 59 ms 564 KB Output is correct
44 Correct 67 ms 348 KB Output is correct
45 Correct 49 ms 568 KB Output is correct
46 Correct 24 ms 568 KB Output is correct
47 Correct 22 ms 348 KB Output is correct
48 Correct 35 ms 348 KB Output is correct
49 Correct 48 ms 436 KB Output is correct
50 Correct 97 ms 604 KB Output is correct
51 Correct 94 ms 600 KB Output is correct
52 Correct 352 ms 816 KB Output is correct
53 Correct 209 ms 812 KB Output is correct
54 Correct 344 ms 604 KB Output is correct
55 Correct 473 ms 820 KB Output is correct
56 Correct 378 ms 612 KB Output is correct
57 Correct 323 ms 816 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 500 ms 820 KB Output is correct
63 Correct 521 ms 812 KB Output is correct
64 Correct 259 ms 812 KB Output is correct
65 Correct 506 ms 816 KB Output is correct
66 Correct 844 ms 812 KB Output is correct
67 Correct 97 ms 604 KB Output is correct
68 Correct 94 ms 600 KB Output is correct
69 Correct 52 ms 348 KB Output is correct
70 Correct 28 ms 572 KB Output is correct
71 Correct 59 ms 348 KB Output is correct
72 Correct 72 ms 344 KB Output is correct
73 Correct 49 ms 344 KB Output is correct
74 Correct 23 ms 344 KB Output is correct
75 Correct 23 ms 604 KB Output is correct
76 Correct 35 ms 348 KB Output is correct
77 Correct 44 ms 348 KB Output is correct
78 Correct 88 ms 344 KB Output is correct
79 Correct 48 ms 572 KB Output is correct
80 Correct 114 ms 564 KB Output is correct
81 Correct 85 ms 344 KB Output is correct
82 Correct 95 ms 592 KB Output is correct
83 Correct 343 ms 600 KB Output is correct
84 Correct 211 ms 600 KB Output is correct
85 Correct 344 ms 600 KB Output is correct
86 Correct 467 ms 816 KB Output is correct
87 Correct 369 ms 604 KB Output is correct
88 Correct 321 ms 816 KB Output is correct
89 Correct 617 ms 820 KB Output is correct
90 Correct 853 ms 848 KB Output is correct
91 Correct 620 ms 816 KB Output is correct
92 Correct 663 ms 816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 58 ms 348 KB Output is correct
3 Correct 27 ms 344 KB Output is correct
4 Correct 62 ms 568 KB Output is correct
5 Correct 67 ms 344 KB Output is correct
6 Correct 49 ms 344 KB Output is correct
7 Correct 24 ms 596 KB Output is correct
8 Correct 22 ms 600 KB Output is correct
9 Correct 36 ms 604 KB Output is correct
10 Correct 45 ms 568 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 52 ms 572 KB Output is correct
13 Correct 28 ms 344 KB Output is correct
14 Correct 59 ms 564 KB Output is correct
15 Correct 67 ms 348 KB Output is correct
16 Correct 49 ms 568 KB Output is correct
17 Correct 24 ms 568 KB Output is correct
18 Correct 22 ms 348 KB Output is correct
19 Correct 35 ms 348 KB Output is correct
20 Correct 48 ms 436 KB Output is correct
21 Correct 97 ms 604 KB Output is correct
22 Correct 94 ms 600 KB Output is correct
23 Correct 352 ms 816 KB Output is correct
24 Correct 209 ms 812 KB Output is correct
25 Correct 344 ms 604 KB Output is correct
26 Correct 473 ms 820 KB Output is correct
27 Correct 378 ms 612 KB Output is correct
28 Correct 323 ms 816 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 52 ms 348 KB Output is correct
31 Correct 27 ms 572 KB Output is correct
32 Correct 59 ms 344 KB Output is correct
33 Correct 68 ms 592 KB Output is correct
34 Correct 50 ms 344 KB Output is correct
35 Correct 24 ms 344 KB Output is correct
36 Correct 22 ms 344 KB Output is correct
37 Correct 38 ms 348 KB Output is correct
38 Correct 45 ms 348 KB Output is correct
39 Correct 98 ms 816 KB Output is correct
40 Correct 94 ms 816 KB Output is correct
41 Correct 343 ms 604 KB Output is correct
42 Correct 209 ms 848 KB Output is correct
43 Correct 355 ms 600 KB Output is correct
44 Correct 468 ms 600 KB Output is correct
45 Correct 370 ms 600 KB Output is correct
46 Correct 322 ms 604 KB Output is correct
47 Correct 648 ms 2024 KB Output is correct
48 Correct 630 ms 1880 KB Output is correct
49 Correct 3899 ms 2024 KB Output is correct
50 Correct 1964 ms 2036 KB Output is correct
51 Correct 4232 ms 2024 KB Output is correct
52 Execution timed out 5037 ms 1884 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 502 ms 816 KB Output is correct
6 Correct 521 ms 604 KB Output is correct
7 Correct 262 ms 816 KB Output is correct
8 Correct 509 ms 604 KB Output is correct
9 Correct 850 ms 816 KB Output is correct
10 Correct 100 ms 944 KB Output is correct
11 Correct 94 ms 812 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 506 ms 812 KB Output is correct
17 Correct 523 ms 600 KB Output is correct
18 Correct 263 ms 820 KB Output is correct
19 Correct 505 ms 604 KB Output is correct
20 Correct 859 ms 824 KB Output is correct
21 Correct 99 ms 600 KB Output is correct
22 Correct 94 ms 816 KB Output is correct
23 Execution timed out 5057 ms 1884 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 58 ms 348 KB Output is correct
3 Correct 27 ms 344 KB Output is correct
4 Correct 62 ms 568 KB Output is correct
5 Correct 67 ms 344 KB Output is correct
6 Correct 49 ms 344 KB Output is correct
7 Correct 24 ms 596 KB Output is correct
8 Correct 22 ms 600 KB Output is correct
9 Correct 36 ms 604 KB Output is correct
10 Correct 45 ms 568 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 52 ms 572 KB Output is correct
13 Correct 28 ms 344 KB Output is correct
14 Correct 59 ms 564 KB Output is correct
15 Correct 67 ms 348 KB Output is correct
16 Correct 49 ms 568 KB Output is correct
17 Correct 24 ms 568 KB Output is correct
18 Correct 22 ms 348 KB Output is correct
19 Correct 35 ms 348 KB Output is correct
20 Correct 48 ms 436 KB Output is correct
21 Correct 97 ms 604 KB Output is correct
22 Correct 94 ms 600 KB Output is correct
23 Correct 352 ms 816 KB Output is correct
24 Correct 209 ms 812 KB Output is correct
25 Correct 344 ms 604 KB Output is correct
26 Correct 473 ms 820 KB Output is correct
27 Correct 378 ms 612 KB Output is correct
28 Correct 323 ms 816 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 52 ms 348 KB Output is correct
31 Correct 27 ms 572 KB Output is correct
32 Correct 59 ms 344 KB Output is correct
33 Correct 68 ms 592 KB Output is correct
34 Correct 50 ms 344 KB Output is correct
35 Correct 24 ms 344 KB Output is correct
36 Correct 22 ms 344 KB Output is correct
37 Correct 38 ms 348 KB Output is correct
38 Correct 45 ms 348 KB Output is correct
39 Correct 98 ms 816 KB Output is correct
40 Correct 94 ms 816 KB Output is correct
41 Correct 343 ms 604 KB Output is correct
42 Correct 209 ms 848 KB Output is correct
43 Correct 355 ms 600 KB Output is correct
44 Correct 468 ms 600 KB Output is correct
45 Correct 370 ms 600 KB Output is correct
46 Correct 322 ms 604 KB Output is correct
47 Correct 648 ms 2024 KB Output is correct
48 Correct 630 ms 1880 KB Output is correct
49 Correct 3899 ms 2024 KB Output is correct
50 Correct 1964 ms 2036 KB Output is correct
51 Correct 4232 ms 2024 KB Output is correct
52 Execution timed out 5037 ms 1884 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 502 ms 816 KB Output is correct
6 Correct 521 ms 604 KB Output is correct
7 Correct 262 ms 816 KB Output is correct
8 Correct 509 ms 604 KB Output is correct
9 Correct 850 ms 816 KB Output is correct
10 Correct 100 ms 944 KB Output is correct
11 Correct 94 ms 812 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 506 ms 812 KB Output is correct
17 Correct 523 ms 600 KB Output is correct
18 Correct 263 ms 820 KB Output is correct
19 Correct 505 ms 604 KB Output is correct
20 Correct 859 ms 824 KB Output is correct
21 Correct 99 ms 600 KB Output is correct
22 Correct 94 ms 816 KB Output is correct
23 Execution timed out 5057 ms 1884 KB Time limit exceeded
24 Halted 0 ms 0 KB -