QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355940 | #8281. Pangu and Stones | ckiseki# | WA | 3ms | 8172kb | C++20 | 1.7kb | 2024-03-17 14:05:26 | 2024-03-17 14:05:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int f = 0;
(..., (cerr << (f++ ? ", " : "") << a));
cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
cerr << "\e[1;33m[ " << s << " ] = [ ";
using namespace experimental;
copy(L, R, make_ostream_joiner(cerr, ", "));
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
const int maxn = 105;
int dp[maxn][maxn][maxn];
int dp2[maxn][maxn];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
int L, R;
cin >> L >> R;
vector<int> a(n), pre(n + 1);
for (int i = 0; i < n; i++) {
cin >> a[i];
pre[i + 1] = pre[i] + a[i];
}
const int inf = 1e9;
for (int l = 0; l <= n; l++)
for (int r = 0; r <= n; r++) {
for (int c = 0; c <= n; c++)
dp[l][r][c] = inf;
dp2[l][r] = inf;
}
for (int l = 0; l <= n; l++)
dp[l][l][0] = 0;
for (int l = 0; l < n; l++)
dp[l][l + 1][1] = dp2[l][l + 1] = 0;
for (int l = n - 1; l >= 0; l--) {
for (int r = l + 1; r <= n; r++) {
for (int c = 1; c <= r - l; c++) {
for (int k = l + 1; k <= r; k++) {
dp[l][r][c] = min(dp[l][r][c], dp2[l][k] + dp[k][r][c - 1]);
}
if (c >= L && c <= R)
dp2[l][r] = min(dp2[l][r], dp[l][r][c] + pre[r] - pre[l]);
}
}
}
if (dp2[0][n] == inf) {
cout << 0 << '\n';
} else {
cout << dp2[0][n] << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
input:
3 2 2 1 2 3
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
3 2 3 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
4 3 3 1 2 3 4
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: -100
Wrong Answer
time: 3ms
memory: 8172kb
input:
100 4 7 570 608 194 26 243 470 418 119 1000 936 440 302 797 155 676 283 869 60 959 793 158 397 808 656 379 316 485 854 753 280 543 435 756 822 106 561 402 347 99 739 8 682 834 549 812 32 338 765 699 575 575 785 171 504 335 113 284 612 276 518 835 677 865 900 687 48 859 179 343 318 626 812 523 11 400...
output:
124078
result:
wrong answer 1st numbers differ - expected: '120446', found: '124078'