QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#621701 | #9442. Music Game | ucup-team4975# | WA | 1ms | 3900kb | C++23 | 1.1kb | 2024-10-08 16:21:40 | 2024-10-08 16:21:41 |
Judging History
answer
#include <bits/stdc++.h>
#define fir first
#define sec second
#define el '\n'
#define FINISH cerr << "FINISH" << endl;
#define debug(x) cerr << #x << " == " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 200020;
void solve()
{
int n, m;
cin >> n;
vector<int> d(n + 1, 0);
for (int i = 1; i < n; i++) {
cin >> d[i];
}
vector dp(n + 1, vector(2020, inf));
for (int i = 0; i <= 2000; i++) {
dp[1][i] = i;
}
for (int i = 1; i < n; i++) {
for (int j = 0; j <= 2000; j++) {
if (j + d[i] <= 2000) {
dp[i + 1][j + d[i]] = min(dp[i + 1][j + d[i]], dp[i][j] + d[i]);
}
if (j - d[i] >= 0) {
dp[i + 1][j - d[i]] = min(dp[i + 1][j - d[i]], dp[i][j]);
}
}
}
int ans = inf;
for (int i = 0; i <= 2000; i++) {
ans = min(ans, dp[n][i]);
}
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3900kb
input:
2 3 3 5 2 4 7
output:
3
result:
wrong answer 1st words differ - expected: '831870305', found: '3'