QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#621701#9442. Music Gameucup-team4975#WA 1ms3900kbC++231.1kb2024-10-08 16:21:402024-10-08 16:21:41

Judging History

你现在查看的是最新测评结果

  • [2024-10-08 16:21:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3900kb
  • [2024-10-08 16:21:40]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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'