QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#688334#5590. Exponent ExchangeTenshi#AC ✓267ms785868kbC++231.7kb2024-10-30 04:49:532024-10-30 04:49:55

Judging History

This is the latest submission verdict.

  • [2024-10-30 04:49:55]
  • Judged
  • Verdict: AC
  • Time: 267ms
  • Memory: 785868kb
  • [2024-10-30 04:49:53]
  • Submitted

answer

#include <bits/stdc++.h>
#include <iostream>
#include <queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

#define sz(x) (long long)(x).size()

int dp[1001][2][100001];
int b, p;

// int func(int onBob, int idx, int a) {
//     if (idx >= 1000) {
//         return max(a, dp[onBob][idx][a]);
//     }
// }

int main() {
    cin >> b >> p;
    vector<int> A(p), B(p);
    rep(i, p) {
        cin >> A[i];
        B[i] = b-A[i]-1;
        if (i==p-1) B[i]++;
    }
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
    rep(i, 1001) rep(k, 2) rep(j, 100001) dp[i][k][j] = 1e9;
    dp[0][0][0] = 0;
    dp[0][1][0] = 0;
    rep(idx, p) {
        rep(onBob, 2) {
            rep(alice, 100001) {
                if (dp[idx][onBob][alice]==1e9) continue;
                
                if (onBob==0){
                    dp[idx+1][0][A[idx]+alice] = min(dp[idx+1][0][A[idx]+alice], dp[idx][onBob][alice]);
                    dp[idx+1][1][A[idx]+alice] = min(dp[idx+1][1][A[idx]+alice], dp[idx][onBob][alice]+1);
                }
                if (onBob==1){
                    dp[idx+1][0][alice+1] = min(dp[idx+1][0][alice+1], dp[idx][onBob][alice]+B[idx]);
                    dp[idx+1][1][alice] = min(dp[idx+1][1][alice], dp[idx][onBob][alice]+B[idx]);
                }
            }
        }
    }
    int mn = 1e9;
    rep(onBob, 2) {
        rep(alice, 100001) {
            if (dp[p][onBob][alice]==1e9) continue;
            mn = min(mn, max(dp[p][onBob][alice], alice));
            // cout << onBob << ' ' << alice << endl;
            // cout << dp[p][onBob][alice] << endl;
        }
    }
    cout << mn << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 95ms
memory: 785508kb

input:

10 5
4 2 7 8 6

output:

7

result:

ok single line: '7'

Test #2:

score: 0
Accepted
time: 95ms
memory: 785828kb

input:

2 100
1 1 1 1 0 0 1 1 1 0 1 1 1 0 0 1 0 0 1 0 0 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 0 0 0 1 0 1 1 1 1 0 1 1 0 1 1 0 0 0 0 1 1 1

output:

19

result:

ok single line: '19'

Test #3:

score: 0
Accepted
time: 120ms
memory: 785792kb

input:

2 100
1 1 0 1 0 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 0 0 0 1 1 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 1 0 1 0 1 1 1 0 1 0 1 0 1 0 1 1 0 0 1 0 0

output:

20

result:

ok single line: '20'

Test #4:

score: 0
Accepted
time: 267ms
memory: 785520kb

input:

100 1000
27 21 72 90 53 34 19 36 54 48 74 65 73 50 86 92 85 84 1 57 16 40 16 97 39 62 8 11 31 4 29 56 54 29 59 22 84 65 91 25 94 96 20 30 55 62 17 19 15 40 79 75 2 74 37 53 94 69 57 21 21 39 71 2 50 12 72 98 18 84 38 81 81 11 6 69 49 52 47 25 86 10 72 74 29 16 99 28 8 9 95 62 39 25 3 20 35 20 72 82 ...

output:

12638

result:

ok single line: '12638'

Test #5:

score: 0
Accepted
time: 79ms
memory: 785824kb

input:

2 100
1 1 1 1 0 1 1 1 1 0 0 1 0 1 1 0 0 0 0 1 0 0 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 1 0 1 1 1 0 0 1 1 0 0 1 1 0 0 1 0 0 1 0 1 0 1 1 1 0 0 1 0 1 0 1 0 1 0 1

output:

21

result:

ok single line: '21'

Test #6:

score: 0
Accepted
time: 148ms
memory: 785620kb

input:

60 336
41 4 6 27 26 6 16 48 30 53 18 29 57 19 1 52 42 50 34 21 40 43 18 44 56 22 22 16 32 59 17 59 6 31 15 18 39 21 23 12 20 3 26 32 7 30 26 43 44 16 48 21 17 20 12 33 4 52 39 24 44 50 36 34 23 10 13 23 31 50 49 11 53 56 46 36 47 30 59 0 0 4 0 11 25 12 53 42 49 35 14 16 27 28 56 44 48 17 57 2 37 38 ...

output:

2490

result:

ok single line: '2490'

Test #7:

score: 0
Accepted
time: 143ms
memory: 785512kb

input:

17 302
15 16 1 13 9 15 7 11 3 15 15 3 3 16 4 14 13 11 0 15 14 0 6 3 13 5 11 5 15 1 3 0 15 13 15 4 9 11 1 16 4 3 8 8 9 13 10 5 16 10 16 15 12 14 11 12 7 3 6 1 5 4 3 12 6 9 6 12 1 11 10 8 7 0 11 8 12 15 11 7 10 12 11 0 11 13 9 7 10 14 6 15 1 12 12 4 9 5 12 2 2 5 8 6 6 0 6 10 4 16 3 15 5 9 12 1 2 5 13 ...

output:

673

result:

ok single line: '673'

Test #8:

score: 0
Accepted
time: 156ms
memory: 785688kb

input:

11 608
5 10 0 10 2 9 9 6 0 5 0 4 10 2 9 5 7 10 2 6 7 10 7 5 1 4 1 0 3 1 9 7 4 3 5 6 0 6 9 10 9 5 3 4 6 7 10 1 0 5 3 10 10 0 7 3 5 3 1 2 9 5 10 5 7 4 7 5 1 0 6 5 10 2 5 1 5 7 3 10 10 5 0 9 6 0 9 6 10 0 9 0 5 6 8 3 8 4 3 9 7 10 1 10 2 10 1 3 8 2 9 5 1 1 2 9 2 0 10 0 1 7 5 9 3 2 5 1 10 8 8 1 6 2 4 7 9 ...

output:

828

result:

ok single line: '828'

Test #9:

score: 0
Accepted
time: 176ms
memory: 785868kb

input:

89 462
88 62 73 50 60 23 24 81 21 59 53 50 41 46 11 86 76 64 32 42 34 6 81 75 0 43 37 35 33 11 15 84 12 38 43 17 81 11 68 7 16 23 13 27 21 56 71 77 64 55 64 42 71 18 2 17 78 17 58 31 60 29 65 85 34 74 8 74 1 17 77 30 51 50 49 19 5 29 33 88 86 17 28 76 3 39 68 40 77 48 28 2 82 44 85 43 42 0 49 46 29 ...

output:

5298

result:

ok single line: '5298'

Test #10:

score: 0
Accepted
time: 180ms
memory: 785564kb

input:

18 630
1 0 10 9 3 2 13 11 3 14 1 0 5 0 17 3 10 16 16 6 4 13 1 9 7 12 7 4 17 11 5 12 7 0 12 15 9 15 3 14 7 8 15 5 8 9 15 9 3 6 2 17 14 8 8 12 13 15 6 15 14 1 9 14 0 17 4 5 10 7 13 14 0 7 16 9 17 17 4 9 13 3 2 12 2 12 9 6 17 1 14 2 11 15 8 17 8 3 16 12 6 14 10 0 1 8 4 14 9 10 12 3 5 17 12 4 13 10 13 1...

output:

1430

result:

ok single line: '1430'

Test #11:

score: 0
Accepted
time: 134ms
memory: 785624kb

input:

49 354
20 22 42 12 21 21 45 17 29 38 23 21 21 42 26 45 3 45 16 3 10 17 2 21 21 14 21 1 37 6 40 22 26 36 47 8 39 30 39 32 14 19 13 37 1 43 14 26 16 31 8 37 23 29 13 17 6 7 27 24 21 35 37 43 48 41 37 48 15 1 8 21 38 13 46 34 34 0 35 32 0 28 42 36 3 46 40 12 28 33 46 43 10 35 12 18 42 25 26 0 17 8 1 2 ...

output:

2117

result:

ok single line: '2117'

Test #12:

score: 0
Accepted
time: 63ms
memory: 785632kb

input:

30 49
4 0 4 2 26 19 27 25 10 21 12 24 3 29 8 5 29 16 19 5 5 19 17 20 3 14 22 18 29 29 1 7 5 2 26 26 11 21 17 29 5 10 26 3 2 18 17 20 12

output:

164

result:

ok single line: '164'

Test #13:

score: 0
Accepted
time: 176ms
memory: 785640kb

input:

50 494
27 34 10 23 15 6 2 49 32 12 42 4 8 12 6 7 10 1 14 17 33 30 12 37 40 38 37 41 43 8 46 9 38 48 30 4 24 47 17 11 13 1 11 7 15 33 45 33 7 37 37 27 34 12 7 11 7 41 26 6 36 47 44 8 10 5 9 7 14 17 8 17 13 28 29 6 12 29 23 43 32 32 19 44 18 46 30 42 41 43 38 20 48 4 44 30 45 25 16 21 9 45 15 6 28 39 ...

output:

3219

result:

ok single line: '3219'

Test #14:

score: 0
Accepted
time: 120ms
memory: 785828kb

input:

28 137
14 10 21 12 16 18 13 6 19 5 12 10 21 24 25 2 2 14 18 7 8 27 19 8 15 14 27 25 22 11 4 25 20 7 14 15 12 25 10 19 18 1 22 18 8 13 2 9 14 13 26 16 12 17 19 15 10 5 5 19 24 11 16 11 6 0 27 23 1 10 10 19 12 20 12 22 1 23 4 25 24 14 23 18 0 10 19 16 12 10 17 4 14 24 21 0 0 22 16 17 13 10 11 24 6 26 ...

output:

534

result:

ok single line: '534'

Test #15:

score: 0
Accepted
time: 111ms
memory: 785664kb

input:

28 179
9 20 19 27 25 14 17 11 22 3 6 23 10 8 22 12 20 21 26 15 24 19 7 12 10 11 3 9 20 3 17 16 11 1 23 11 21 12 25 18 18 1 13 16 3 11 14 13 10 25 22 4 27 8 5 12 4 18 23 21 6 16 16 2 19 12 6 12 14 27 27 15 3 12 0 16 27 11 1 7 25 13 2 17 10 17 17 5 9 15 19 12 27 3 8 1 7 22 20 7 5 26 15 6 0 18 16 8 2 3...

output:

657

result:

ok single line: '657'

Test #16:

score: 0
Accepted
time: 183ms
memory: 785792kb

input:

6 448
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ...

output:

360

result:

ok single line: '360'

Test #17:

score: 0
Accepted
time: 120ms
memory: 785640kb

input:

50 206
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

1

result:

ok single line: '1'

Test #18:

score: 0
Accepted
time: 96ms
memory: 785604kb

input:

99 191
62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62...

output:

4357

result:

ok single line: '4357'

Test #19:

score: 0
Accepted
time: 218ms
memory: 785608kb

input:

79 828
43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43...

output:

15996

result:

ok single line: '15996'

Test #20:

score: 0
Accepted
time: 196ms
memory: 785800kb

input:

41 654
13 13 37 13 13 13 13 37 13 13 37 37 13 37 13 13 37 37 37 37 37 37 13 13 37 37 37 13 37 37 13 13 13 13 13 13 37 37 37 13 37 37 13 37 13 13 13 13 37 37 37 13 13 37 13 13 37 13 37 37 37 13 13 37 37 37 13 13 37 13 13 13 37 13 37 37 37 37 13 37 37 37 13 13 37 13 13 13 37 13 13 13 13 37 13 13 13 13...

output:

3437

result:

ok single line: '3437'

Test #21:

score: 0
Accepted
time: 168ms
memory: 785632kb

input:

77 455
49 59 49 49 59 59 59 59 59 49 59 49 59 49 59 59 49 49 59 49 49 59 49 59 59 49 49 49 49 49 49 59 49 49 49 49 59 49 49 59 49 59 49 49 49 59 49 49 49 59 59 49 49 59 59 49 59 59 59 49 59 49 49 59 59 59 59 49 59 49 59 59 49 49 49 49 49 59 59 59 49 49 49 59 49 49 49 59 49 49 59 49 49 59 59 59 49 49...

output:

6567

result:

ok single line: '6567'

Test #22:

score: 0
Accepted
time: 220ms
memory: 785828kb

input:

18 874
1 14 14 14 14 1 14 1 1 14 1 1 14 1 1 14 1 1 14 14 14 14 14 14 1 1 1 14 1 14 14 14 1 14 14 14 1 14 1 14 1 1 14 1 1 1 1 1 14 1 14 14 14 14 1 14 1 1 14 14 14 1 14 1 1 1 1 14 14 1 14 14 1 1 1 14 1 1 14 1 14 1 14 14 14 1 1 1 1 1 1 14 14 1 1 1 1 1 1 1 14 14 14 1 14 14 14 1 14 14 14 14 1 1 14 14 14 ...

output:

1298

result:

ok single line: '1298'

Test #23:

score: 0
Accepted
time: 237ms
memory: 785576kb

input:

44 821
10 10 10 43 10 10 10 10 10 10 43 43 43 10 43 10 10 43 10 10 10 10 43 43 43 10 43 43 10 10 10 43 10 43 43 43 43 43 10 10 43 10 10 43 10 10 10 10 10 10 10 10 10 10 43 10 10 43 43 43 10 10 43 10 10 10 10 43 43 10 43 43 10 10 43 10 43 10 10 43 10 10 10 43 10 43 10 10 10 10 10 10 43 10 10 10 10 10...

output:

3311

result:

ok single line: '3311'

Test #24:

score: 0
Accepted
time: 76ms
memory: 785572kb

input:

41 47
22 9 22 22 22 9 22 22 9 22 9 9 9 9 9 22 9 22 22 9 9 9 9 9 9 9 9 22 9 9 22 9 22 9 22 9 9 22 22 9 22 9 22 9 9 9 22

output:

318

result:

ok single line: '318'

Test #25:

score: 0
Accepted
time: 168ms
memory: 785664kb

input:

45 552
7 7 7 37 7 7 7 37 37 7 7 37 37 7 37 7 37 37 7 37 37 7 7 7 7 7 7 37 37 37 7 37 7 7 37 37 7 7 37 37 7 37 7 7 37 37 7 37 7 7 7 37 37 7 7 7 7 37 37 7 37 7 37 37 37 37 7 7 37 7 37 37 37 7 37 7 7 37 37 37 37 7 7 37 37 37 37 7 37 7 7 7 37 7 7 7 7 37 37 37 7 37 7 37 37 37 7 37 7 7 7 37 37 37 37 37 7 ...

output:

2085

result:

ok single line: '2085'

Test #26:

score: 0
Accepted
time: 95ms
memory: 785604kb

input:

75 202
43 10 10 10 10 10 10 10 10 43 43 43 10 10 10 10 43 43 43 43 43 43 43 43 43 10 43 43 10 43 43 43 10 43 10 10 43 43 43 10 43 10 10 10 10 10 10 10 43 10 43 43 43 10 10 10 43 43 10 10 10 43 10 10 10 43 10 10 10 10 43 43 43 10 10 10 10 10 10 10 43 10 10 10 10 10 10 43 43 43 10 10 43 10 10 10 43 43...

output:

2104

result:

ok single line: '2104'

Test #27:

score: 0
Accepted
time: 63ms
memory: 785852kb

input:

10 4
9 9 9 2

output:

2

result:

ok single line: '2'

Test #28:

score: 0
Accepted
time: 255ms
memory: 785672kb

input:

100 1000
67 1 90 44 92 70 22 92 37 68 53 9 84 34 52 64 23 95 84 93 38 2 60 1 40 16 46 8 46 80 68 53 20 55 24 58 17 71 22 41 63 64 26 57 88 68 58 16 77 57 28 38 29 11 63 48 7 8 42 49 53 66 64 85 75 18 58 96 80 36 80 42 68 96 13 38 84 93 78 22 31 73 91 82 41 25 65 15 7 95 54 88 89 39 26 65 61 52 83 62...

output:

12267

result:

ok single line: '12267'