Submission #3244252
Source Code Expand
/** * File : C.cpp * Author : Kazune Takahashi * Created : 9/22/2018, 9:12:06 PM * Powered by Visual Studio Code */ #include <iostream> #include <iomanip> // << fixed << setprecision(xxx) #include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ; #include <vector> #include <string> // to_string(nnn) // substr(m, n) // stoi(nnn) #include <complex> #include <tuple> #include <queue> #include <stack> #include <map> // if (M.find(key) != M.end()) { } #include <set> #include <functional> #include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725)); #include <chrono> // std::chrono::system_clock::time_point start_time, end_time; // start = std::chrono::system_clock::now(); // double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count(); #include <cctype> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> using namespace std; #define DEBUG 0 // change 0 -> 1 if we need debug. typedef long long ll; // const int dx[4] = {1, 0, -1, 0}; // const int dy[4] = {0, 1, 0, -1}; // const int C = 1e6+10; const ll MOD = 1000000007; int N, K; ll A[100]; ll cnt[100]; ll DP[50][5010][2]; int main() { cin >> N >> K; for (auto i = 1; i <= N; i++) { cin >> A[i]; } for (auto i = 1; i <= N; i++) { cnt[i] = 0; while (A[i] > 0) { A[i] /= 2; cnt[i]++; } } fill(&DP[0][0][0], &DP[0][0][0] + 50 * 5010 * 2, 0); DP[0][0][0] = 1; K = min(K, 5000); for (auto i = 1; i <= N; i++) { ll C = cnt[i]; for (auto j = 0; j <= K; j++) { /* DP[i][j][0] = 0; int ind = j - 1; if (ind >= 0) { DP[i][j][0] += DP[i][ind][0]; DP[i][j][0] %= MOD; DP[i][j][0] += MOD - DP[i - 1][ind][0]; DP[i][j][0] %= MOD; } ind = j - 1 + C; if (0 <= ind && ind <= K) { DP[i][j][0] += DP[i][ind][0]; DP[i][j][0] %= MOD; } DP[i][j][1] = 0; ind = j - 1; if (ind >= 0) { DP[i][j][1] += DP[i][ind][1]; DP[i][j][1] %= MOD; DP[i][j][1] += MOD - DP[i - 1][ind][1]; DP[i][j][1] %= MOD; } ind = j + C; if (0 <= ind && ind <= K) { DP[i][j][1] += DP[i][ind][1]; DP[i][j][1] %= MOD; } ind = j - C; if (0 <= ind && ind <= K) { DP[i][j][1] += DP[i][ind][0]; DP[i][j][1] %= MOD; } */ DP[i][j][0] = 0; for (auto k = 0; k <= C - 1; k++) { if (0 <= j - k && j - k <= K) { DP[i][j][0] += DP[i - 1][j - k][0]; DP[i][j][0] %= MOD; } } DP[i][j][1] = 0; for (auto k = 0; k <= C; k++) { if (0 <= j - k && j - k <= K) { DP[i][j][1] += DP[i - 1][j - k][1]; DP[i][j][1] %= MOD; } } if (j - C >= 0) { DP[i][j][1] += DP[i - 1][j - C][0]; DP[i][j][1] %= MOD; } } } ll ans = DP[N][K][0]; for (auto i = 0; i <= K; i++) { ans += DP[N][i][1]; ans %= MOD; } cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - 半分 |
User | kazunetakahashi |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 3276 Byte |
Status | RE |
Exec Time | 261 ms |
Memory | 4224 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 500 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.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, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 3 ms | 4096 KB |
02.txt | RE | 130 ms | 4096 KB |
03.txt | RE | 250 ms | 4096 KB |
04.txt | RE | 261 ms | 4096 KB |
05.txt | RE | 250 ms | 4096 KB |
06.txt | RE | 176 ms | 4096 KB |
07.txt | RE | 256 ms | 4096 KB |
08.txt | RE | 174 ms | 4096 KB |
09.txt | RE | 192 ms | 4096 KB |
10.txt | RE | 187 ms | 4096 KB |
11.txt | AC | 3 ms | 4096 KB |
12.txt | AC | 3 ms | 4224 KB |
13.txt | AC | 3 ms | 4224 KB |
14.txt | AC | 3 ms | 4096 KB |
15.txt | AC | 3 ms | 4096 KB |
16.txt | AC | 4 ms | 4224 KB |
17.txt | RE | 179 ms | 4096 KB |
18.txt | RE | 119 ms | 4096 KB |
19.txt | RE | 177 ms | 4096 KB |
20.txt | RE | 131 ms | 4096 KB |
21.txt | RE | 183 ms | 4096 KB |
22.txt | RE | 112 ms | 4096 KB |
23.txt | RE | 179 ms | 4096 KB |
24.txt | RE | 126 ms | 4096 KB |
25.txt | RE | 118 ms | 4096 KB |
26.txt | RE | 119 ms | 4096 KB |
27.txt | RE | 125 ms | 4096 KB |
28.txt | RE | 235 ms | 4096 KB |
29.txt | RE | 236 ms | 4096 KB |
30.txt | AC | 3 ms | 4096 KB |
31.txt | AC | 3 ms | 4224 KB |
32.txt | RE | 111 ms | 4096 KB |
sample-01.txt | AC | 3 ms | 4096 KB |
sample-02.txt | AC | 3 ms | 4096 KB |
sample-03.txt | AC | 3 ms | 4224 KB |
sample-04.txt | AC | 25 ms | 4096 KB |