Submission #1826134
Source Code Expand
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<ll,ll> ii; typedef vector<int> vi; typedef long double ld; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; typedef set<int>::iterator sit; typedef map<int,int>::iterator mit; typedef vector<int>::iterator vit; const int MOD = (1e9 + 7); int add(int a, int b) { a+=b; while(a>=MOD) a-=MOD; return a; } int mult(int a, int b) { return (a*1LL*b)%MOD; } int modpow(int a, int b) { int r=1; while(b) { if(b&1) r=mult(r,a); a=mult(a,a); b>>=1; } return r; } struct Combi { vector<int> fact; vector<int> ifact; vector<int> inv; vector<int> pow2; int choose(int a, int b) { if(a<b) return 0; if(b==0) return 1; if(a==b) return 1; return mult(fact[a],mult(ifact[b],ifact[a-b])); } int inverse(int a) { return modpow(a,MOD-2); } void init(int _n) { fact.clear(); ifact.clear(); inv.clear(); pow2.clear(); fact.resize(_n+1); ifact.resize(_n+1); inv.resize(_n+1); pow2.resize(_n+1); pow2[0]=1; ifact[0]=1; fact[0]=1; for(int i=1;i<=_n;i++) { pow2[i]=add(pow2[i-1],pow2[i-1]); fact[i]=mult(fact[i-1],i); } ifact[_n] = inverse(fact[_n]); for(int i=_n-1;i>=1;i--) { ifact[i] = mult(ifact[i + 1], i + 1); } for(int i=1;i<=_n;i++) { inv[i] = mult(fact[i-1],ifact[i]); } } }; Combi combi; int dp[2111][2111]; int sum[2111][2111]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); combi.init(4010); int n,k; cin>>n>>k; if(n==1) { cout<<1<<'\n'; return 0; } int coeff=1; if(k<n) coeff=combi.pow2[n-k-1]; for(int i=1;i<=n-1;i++) dp[0][i]=1; for(int i=1;i<k;i++) { for(int j=n-i-1;j>=(i==n-1?0:1);j--) { if(j==n-i-1) dp[i][j]=dp[i-1][j+1]; else dp[i][j]=dp[i][j+1]; dp[i][j]=add(dp[i][j],dp[i-1][j]); } } int ans=dp[k-1][(k==n?0:1)]; ans=mult(ans,coeff); cout<<ans<<'\n'; }
Submission Info
Submission Time | |
---|---|
Task | F - Solitaire |
User | zscoder |
Language | C++14 (GCC 5.4.1) |
Score | 1200 |
Code Size | 2277 Byte |
Status | AC |
Exec Time | 18 ms |
Memory | 18816 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1200 / 1200 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt |
All | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_example_01.txt | AC | 2 ms | 2432 KB |
00_example_02.txt | AC | 2 ms | 2432 KB |
00_example_03.txt | AC | 12 ms | 10624 KB |
01.txt | AC | 2 ms | 2432 KB |
02.txt | AC | 6 ms | 8576 KB |
03.txt | AC | 2 ms | 2432 KB |
04.txt | AC | 2 ms | 2432 KB |
05.txt | AC | 1 ms | 384 KB |
06.txt | AC | 2 ms | 2432 KB |
07.txt | AC | 2 ms | 2432 KB |
08.txt | AC | 2 ms | 2432 KB |
09.txt | AC | 16 ms | 16768 KB |
10.txt | AC | 2 ms | 2432 KB |
11.txt | AC | 2 ms | 2432 KB |
12.txt | AC | 16 ms | 16768 KB |
13.txt | AC | 2 ms | 2432 KB |
14.txt | AC | 10 ms | 8576 KB |
15.txt | AC | 4 ms | 6528 KB |
16.txt | AC | 10 ms | 8576 KB |
17.txt | AC | 8 ms | 6528 KB |
18.txt | AC | 14 ms | 12672 KB |
19.txt | AC | 13 ms | 10624 KB |
20.txt | AC | 8 ms | 6528 KB |
21.txt | AC | 1 ms | 384 KB |
22.txt | AC | 18 ms | 18816 KB |
23.txt | AC | 2 ms | 2432 KB |