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 ll long long
#define FORI(i, n) for(ll i = 0; i < n; i++)
#define FOR(i, n) for(ll i = 1; i <= n; i++)
typedef vector<ll> vl;
typedef set<ll> setl;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define pll pair<ll, ll>
#define db double
#define nll cout << "\n"
#define nl "\n"
#define sync ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const ll MOD = 1e9 + 7;
const int MAX = 200 + 5;
ll n, m, k, res;
ll dp[MAX][MAX][MAX][2];
ll start, finish;
vl path;
void dfs(ll v, ll cnt, ll c, vector < ll > used){
if(cnt == n - 1){
if(v == finish)
res++;
return;
}
if(c != 1){
for(ll i = v + 1; i <= n; i++){
if(!used[i]){
path.push_back(i);
used[i] = 1;
dfs(i, cnt + 1, 1, used);
path.pop_back();
used[i] = 0;
}
}
}
if(c != 0){
for(ll i = v - 1; i >= 1; i--){
if(!used[i]){
path.push_back(i);
used[i] = 1;
dfs(i, cnt + 1, 0, used);
path.pop_back();
used[i] = 0;
}
}
}
}
void solve(){
cin >> n >> start >> finish;
vector < ll > usedd(n + 1, 0);
path.push_back(start);
usedd[start] = 1;
dfs(start, 0, -23, usedd);
cout << res;
}
signed main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
sync;
ll t = 1;
// cin >> t;
FOR(i, t){
// cout << "Case #" << i << ": ";
solve();
}
}
# | 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... |