답안 #1019403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1019403 2024-07-10T19:15:48 Z Nicolaikrob Feast (NOI19_feast) C++17
100 / 100
198 ms 10508 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1LL<<50;

ll n, k;
vector<ll> PS, DP, C;

ll sol(ll g) {
    ll b = PS[n], c = 0;
    for(int i = 1; i <= n; i++) {
        if(DP[i-1] >= b-(PS[n]-PS[i])-g)
            DP[i] = DP[i-1],
            C[i] = C[i-1];
        else
            DP[i] = b-(PS[n]-PS[i])-g,
            C[i] = c+1;

        if(b < DP[i]+PS[n]-PS[i])
            b = DP[i]+PS[n]-PS[i], c = C[i];
    }
    return C[n];
}

int main() {
    cin >> n >> k;
    PS.resize(n+1, 0);
    DP.resize(n+1, 0);
    C.resize(n+1, 0);
    for(int i = 1; i <= n; i++)
        cin >> PS[i], PS[i] += PS[i-1];
    ll l = 0, u = inf;
    while(l < u) {
        ll g = (l+u)/2;
        ll c = sol(g);
        if(c == k) l = u = g;
        if(c > k) l = g;
        if(c < k) u = g;
    }
    sol(l);
    cout << DP[n]+k*l;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 9804 KB Output is correct
2 Correct 106 ms 10068 KB Output is correct
3 Correct 99 ms 10320 KB Output is correct
4 Correct 109 ms 10064 KB Output is correct
5 Correct 117 ms 10064 KB Output is correct
6 Correct 96 ms 10068 KB Output is correct
7 Correct 99 ms 9812 KB Output is correct
8 Correct 137 ms 10064 KB Output is correct
9 Correct 108 ms 10072 KB Output is correct
10 Correct 99 ms 10176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 8284 KB Output is correct
2 Correct 54 ms 8560 KB Output is correct
3 Correct 51 ms 8188 KB Output is correct
4 Correct 71 ms 8284 KB Output is correct
5 Correct 74 ms 9936 KB Output is correct
6 Correct 53 ms 8276 KB Output is correct
7 Correct 67 ms 8540 KB Output is correct
8 Correct 84 ms 10068 KB Output is correct
9 Correct 114 ms 9808 KB Output is correct
10 Correct 68 ms 8532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 10188 KB Output is correct
2 Correct 98 ms 10064 KB Output is correct
3 Correct 95 ms 10324 KB Output is correct
4 Correct 95 ms 10116 KB Output is correct
5 Correct 93 ms 10164 KB Output is correct
6 Correct 99 ms 10200 KB Output is correct
7 Correct 109 ms 10404 KB Output is correct
8 Correct 101 ms 10172 KB Output is correct
9 Correct 107 ms 10508 KB Output is correct
10 Correct 102 ms 10372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 444 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 444 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 428 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 444 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 428 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 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 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 9804 KB Output is correct
2 Correct 106 ms 10068 KB Output is correct
3 Correct 99 ms 10320 KB Output is correct
4 Correct 109 ms 10064 KB Output is correct
5 Correct 117 ms 10064 KB Output is correct
6 Correct 96 ms 10068 KB Output is correct
7 Correct 99 ms 9812 KB Output is correct
8 Correct 137 ms 10064 KB Output is correct
9 Correct 108 ms 10072 KB Output is correct
10 Correct 99 ms 10176 KB Output is correct
11 Correct 57 ms 8284 KB Output is correct
12 Correct 54 ms 8560 KB Output is correct
13 Correct 51 ms 8188 KB Output is correct
14 Correct 71 ms 8284 KB Output is correct
15 Correct 74 ms 9936 KB Output is correct
16 Correct 53 ms 8276 KB Output is correct
17 Correct 67 ms 8540 KB Output is correct
18 Correct 84 ms 10068 KB Output is correct
19 Correct 114 ms 9808 KB Output is correct
20 Correct 68 ms 8532 KB Output is correct
21 Correct 106 ms 10188 KB Output is correct
22 Correct 98 ms 10064 KB Output is correct
23 Correct 95 ms 10324 KB Output is correct
24 Correct 95 ms 10116 KB Output is correct
25 Correct 93 ms 10164 KB Output is correct
26 Correct 99 ms 10200 KB Output is correct
27 Correct 109 ms 10404 KB Output is correct
28 Correct 101 ms 10172 KB Output is correct
29 Correct 107 ms 10508 KB Output is correct
30 Correct 102 ms 10372 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 444 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 428 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 432 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 2 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 2 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 135 ms 10064 KB Output is correct
62 Correct 172 ms 10324 KB Output is correct
63 Correct 167 ms 10068 KB Output is correct
64 Correct 198 ms 10324 KB Output is correct
65 Correct 138 ms 10216 KB Output is correct
66 Correct 142 ms 10320 KB Output is correct
67 Correct 121 ms 10068 KB Output is correct
68 Correct 134 ms 10320 KB Output is correct
69 Correct 100 ms 10228 KB Output is correct
70 Correct 112 ms 10128 KB Output is correct