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;
#define endl '\n'
#define pb push_back
#define ll long long
#define int long long
const long long inf=1e18;
const int MOD=1e9+7;
const int N=41;
int n,cs,cf,ans=0;
bool s[N];
void func(int i,int cnt,bool flag){
if(cnt==n){
if(i==cf){
ans++;
}
return;
}
if(flag){
for(int j=i+1;j<=n;j++){
if(!s[j]){
if(j==cf && cnt<n-1)continue;
s[j]=1;
cnt++;
func(j,cnt,0);
cnt--;
s[j]=0;
}
}
}
else{
for(int j=i-1;j>0;j--){
if(!s[j]){
if(j==cf && cnt<n-1)continue;
s[j]=1;
cnt++;
func(j,cnt,1);
cnt--;
s[j]=0;
}
}
}
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>cs>>cf;
s[cs]=1;
func(cs,1,0);
for(int i=0;i<=n;i++)s[i]=0;
s[cs]=1;
func(cs,1,1);
cout<<ans;
}
# | 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... |