QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#252035#7560. Computer NetworkLin1043#WA 0ms3620kbC++20983b2023-11-15 14:51:592023-11-15 14:51:59

Judging History

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

  • [2023-11-15 14:51:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3620kb
  • [2023-11-15 14:51:59]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 23 + 5;

int n;
long long a[N] , b[N];
int ans = 0;

void dfs(int cur , int step) {
	if (step >= ans) return ;
	// cout << cur << ' ' << step << endl;
	// for (int i = 1 ; i <= n ; i++) {
	// 	cout << b[i] << ' ';
	// }
	// cout << endl;
	if (cur == n + 1) {
		ans = min(ans , step);
		return ;
	}
	if (b[cur] == 0) {
		for (int i = cur + 1 ; i <= n + 1 ; i++) {
			if (b[i] != 0) {
				dfs(i , step);
				break;
			}
		}
	} else {
		for (int i = cur ; i <= n ; i++) {
			// cout << i << endl;
			int v = b[cur];
			b[cur] -= v , b[i + 1] += v;
			dfs(cur + 1 , step + 1);
			b[cur] += v , b[i + 1] -= v;
		}
	}
}

int main() {
	cin.tie(nullptr)->sync_with_stdio(0);
	cin >> n;
	for (int i = 1 ; i <= n ; i++) {
		cin >> a[i];
	}
	for (int i = 1 ; i <= n ; i++) {
		b[i] = a[i] - a[i - 1];
	}
	b[n + 1] = 1e18;
	ans = n;
	dfs(1 , 0);
	cout << ans << '\n';
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3620kb

input:

5
1 2 3 4 5
6 6 6 6 7

output:

5

result:

wrong answer 1st numbers differ - expected: '9', found: '5'