Submission #1162849
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; const int N = 2005; int f[N][N], d[2*N][N]; int main() { int a, b, k; cin >> a >> b >> k; if (!a || !b) { cout << 1 << endl; return 0; } for (int i = 0; i <= a; ++i) { for (int j = 0; j <= b; ++j) { if (!i && !j) { f[i][j] = 1; d[i][j] = 1; continue; } int start = i - min(i, k - 1); int finish = i - max((k - 1) - j, 0); if (finish >= start && (i + j - (k - 1)) >= 0) { f[i][j] = (f[i][j] + d[i + j - (k - 1)][finish]) % mod; if (start > 0) { f[i][j] = (f[i][j] + (mod - d[i + j - (k - 1)][start-1])) % mod; } } d[i + j][i] = f[i][j]; if (i > 0) { d[i + j][i] = (d[i + j][i] + d[i + j][i - 1]) % mod; } } } int result = 0; for (int x = 0; x <= a; x += k - 1) { for (int y = 0; y <= b; y += k - 1) { int i = a - x; int j = b - y; int start = i - min(i, k - 1); int finish = i - max(k - j, 1); if (finish >= start && (i + j - k) >= 0) { result = (result + d[i + j - k][finish]) % mod; if (start > 0) { result = (result + (mod - d[i + j - k][start-1])) % mod; } } } } cout << result << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Eternal Average |
User | nobik |
Language | C++14 (GCC 5.4.1) |
Score | 1600 |
Code Size | 1251 Byte |
Status | AC |
Exec Time | 111 ms |
Memory | 46464 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1600 / 1600 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.txt |
All | 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, 24.txt, s1.txt, s2.txt, s3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 2 ms | 2304 KB |
02.txt | AC | 111 ms | 46464 KB |
03.txt | AC | 2 ms | 2304 KB |
04.txt | AC | 2 ms | 2304 KB |
05.txt | AC | 61 ms | 46464 KB |
06.txt | AC | 5 ms | 17664 KB |
07.txt | AC | 8 ms | 32000 KB |
08.txt | AC | 3 ms | 7552 KB |
09.txt | AC | 56 ms | 46464 KB |
10.txt | AC | 56 ms | 46464 KB |
11.txt | AC | 52 ms | 46464 KB |
12.txt | AC | 39 ms | 46464 KB |
13.txt | AC | 51 ms | 46464 KB |
14.txt | AC | 29 ms | 36224 KB |
15.txt | AC | 45 ms | 42368 KB |
16.txt | AC | 9 ms | 19840 KB |
17.txt | AC | 42 ms | 44416 KB |
18.txt | AC | 16 ms | 25984 KB |
19.txt | AC | 12 ms | 34176 KB |
20.txt | AC | 41 ms | 44416 KB |
21.txt | AC | 2 ms | 2304 KB |
22.txt | AC | 51 ms | 46464 KB |
23.txt | AC | 44 ms | 44416 KB |
24.txt | AC | 40 ms | 42368 KB |
s1.txt | AC | 2 ms | 2304 KB |
s2.txt | AC | 2 ms | 2304 KB |
s3.txt | AC | 3 ms | 5504 KB |