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>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int nax=5e4+5;
const int MOD=1e9+7;
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
long long dp[205][205][205][2];
int n,s,t;
long long dfs(int x,int y,int z,int t){
if(x==1&&y==0&&z==0) return 1;
if(x==0) return 0;
if(dp[x][y][z][t]!=-1) return dp[x][y][z][t];
dp[x][y][z][t]=0;
for (int i = 0; i < n; ++i)
{
if(i==y||i==z) continue;
if((i>s) != t) continue;
dp[x][y][z][t]+= dfs(x-1,((i>y) ? i-1 : i),((z>i) ? z-1 : z), !t);
dp[x][y][z][t]%=MOD;
}
return dp[x][y][z][t];
}
int main()
{
optimise;
cin>>n>>s>>t;
s--;t--;
if(s>t) swap(s,t);
memset(dp,-1,sizeof dp);
cout << (dfs(n,s,t,0)+dfs(n,s,t,1))%MOD <<endl;
}
# | 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... |