This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int lst[25];
int N;
int recurse(int i, int t,bitset<25> v, bool hold){
if(t == N * 2 - 1){
return 0;
}
int ans = 0;
if(!hold && v[i]){
v[i] = false;
hold = true;
}
if(hold && lst[i] == -1){
hold = false;
}
if(t % 2 == 0 && lst[t/2] != -1 && v[i]){
ans += 1;
v[i] = false;
}
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);
deque<int> v;
bitset<25> b;
for(int i = 0; i < N; i++){
scanf(" %d",&lst[i]);
if(lst[i] == 1){
b.set(i,true);
}
}
printf("%d",recurse(0,0,b,false));
}
Compilation message (stderr)
tortoise.cpp: In function 'int main()':
tortoise.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf(" %d",&N);
| ~~~~~^~~~~~~~~~
tortoise.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf(" %d",&lst[i]);
| ~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |