#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++;
ans%=MOD;
}
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 |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
2066 ms |
348 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
2066 ms |
348 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
2066 ms |
348 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |