Submission #1084574
Source Code Expand
#include <bits/stdc++.h> #define SZ(x) ((int) (x).size()) using namespace std; typedef long long i64; const int NMAX = 2005; const int MOD = (int) 1e9 + 7; int dp[NMAX][NMAX]; int pow2[NMAX]; int main() { #ifdef LOCAL_RUN freopen("task.in", "r", stdin); freopen("task.out", "w", stdout); //freopen("task.err", "w", stderr); #endif // ONLINE_JUDGE ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; pow2[0] = 1; for (int i = 1; i <= n; ++i) { pow2[i] = 2 * pow2[i - 1] % MOD; } dp[n][0] = 1; dp[n][1] = -1; int ans = 0; for (int i = n; i >= 0; --i) { for (int j = 1; j <= i; ++j) { dp[i][j] += dp[i][j - 1]; dp[i][j] %= MOD; } if (n - i == k || i == 1) { ans = (int64_t) dp[i][i - 1] * pow2[i - 1] % MOD; break; } else { for (int j = 0; j < i - 1; ++j) { dp[i - 1][j] += dp[i][j]; dp[i - 1][j] %= MOD; dp[i - 1][i] -= dp[i][j]; dp[i - 1][i] %= MOD; } for (int j = 1; j < i; ++j) { dp[i - 1][j - 1] += dp[i][j]; dp[i - 1][j - 1] %= MOD; dp[i - 1][j] -= dp[i][j]; dp[i - 1][j] %= MOD; } } } ans %= MOD; if (ans < 0) ans += MOD; cout << ans << '\n'; }
Submission Info
Submission Time | |
---|---|
Task | F - Solitaire |
User | AndreiNet |
Language | C++14 (GCC 5.4.1) |
Score | 1200 |
Code Size | 1481 Byte |
Status | AC |
Exec Time | 59 ms |
Memory | 14080 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 | 3 ms | 256 KB |
00_example_02.txt | AC | 3 ms | 256 KB |
00_example_03.txt | AC | 40 ms | 8064 KB |
01.txt | AC | 3 ms | 256 KB |
02.txt | AC | 21 ms | 5760 KB |
03.txt | AC | 3 ms | 384 KB |
04.txt | AC | 4 ms | 768 KB |
05.txt | AC | 3 ms | 256 KB |
06.txt | AC | 3 ms | 256 KB |
07.txt | AC | 3 ms | 256 KB |
08.txt | AC | 3 ms | 384 KB |
09.txt | AC | 52 ms | 12288 KB |
10.txt | AC | 3 ms | 256 KB |
11.txt | AC | 3 ms | 256 KB |
12.txt | AC | 52 ms | 12672 KB |
13.txt | AC | 3 ms | 512 KB |
14.txt | AC | 29 ms | 5504 KB |
15.txt | AC | 9 ms | 2816 KB |
16.txt | AC | 30 ms | 5632 KB |
17.txt | AC | 25 ms | 4608 KB |
18.txt | AC | 46 ms | 9728 KB |
19.txt | AC | 42 ms | 8704 KB |
20.txt | AC | 22 ms | 3968 KB |
21.txt | AC | 3 ms | 256 KB |
22.txt | AC | 59 ms | 14080 KB |
23.txt | AC | 3 ms | 256 KB |