#include <bits/stdc++.h>
using namespace std;
int lst[25];
vector<int> v;
int N;
int recurse(int i, int t, vector<int> v, bool hold){
if(t == N * 2 - 1){
return 0;
}
int ans = 0;
if(!hold && v[i] >= 1){
v[i] = v[i] - 1;
hold = true;
}
if(hold && v[i] == -1){
hold = false;
}
if(t % 2 == 0){
ans += v[t / 2];
v[t/2] = 0;
}
if(i == 0){
return ans + recurse(i + 1, t + 1, v, hold);
}
else if(i == N - 1){
return ans + recurse(i - 1, t + 1, v, hold);
}
else{
return ans + min(recurse(i + 1, t + 1,v,hold),recurse(i - 1, t + 1, v, hold));
}
}
int main(){
scanf(" %d",&N);
for(int i = 0; i < N; i++){
scanf(" %d",&lst[i]);
v.push_back(lst[i]);
}
printf("%d",recurse(0,0,v,false));
}
Compilation message
tortoise.cpp: In function 'int main()':
tortoise.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | scanf(" %d",&N);
| ~~~~~^~~~~~~~~~
tortoise.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf(" %d",&lst[i]);
| ~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3060 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3060 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3060 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3060 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3060 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |