QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252035 | #7560. Computer Network | Lin1043# | WA | 0ms | 3620kb | C++20 | 983b | 2023-11-15 14:51:59 | 2023-11-15 14:51:59 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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'