Submission #1030872

#TimeUsernameProblemLanguageResultExecution timeMemory
1030872MarwenElarbi캥거루 (CEOI16_kangaroo)C++17
0 / 100
36 ms63316 KiB
#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=2e3+5; const int MOD=1e9+7; #define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); long long dp[nax][nax][2]; int main() { optimise; int n,s,t; cin>>n>>s>>t; s--;t--; if(s>t) swap(s,t); memset(dp,0,sizeof dp); dp[0][1][(s==0 ? 1 : 0)] = 1; for (int i = 1; i < n; ++i) { for (int j = 1; j < n; ++j) { if(i<s){ dp[i][j][0]+= 1ll * dp[i-1][j+1][0] * (j+1) * (j); dp[i][j][0]+= dp[i-1][j-1][0]; }else if(i==s){ dp[i][j][1]+= 1ll * dp[i-1][j+1][0] * (j+1); dp[i][j][1]+= dp[i-1][j-1][0]; }else if(i<t){ dp[i][j][1]+= 1ll * dp[i-1][j+1][1] * j * j; dp[i][j][1]+=dp[i-1][j-1][1]; }else if(i==t){ dp[i][j][0]+= 1ll* dp[i-1][j+1][1] * j; dp[i][j][0]+=dp[i-1][j][1]; }else{ dp[i][j][0]+= 1ll * dp[i-1][j+1][0] * (j+1) * (j); dp[i][j][0]+= dp[i-1][j-1][0]; } dp[i][j][0]%=MOD; dp[i][j][1]%=MOD; } } cout <<dp[n-1][1][0]<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...