Submission #24951143
Source Code Expand
import java.util.*; public class Main { public static void main(String[] args) { // ---------- // 入力 // ---------- Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.next()); long mod = 1000000000 + 7; // Kは3000以上なら3000にしていい int k = Math.min(Integer.parseInt(sc.next()), 3000); // Aは「0にするのに必要な操作の回数」に置き換えておく int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = getCnt(Long.parseLong(sc.next())); } // ---------- // DP1回目 // ---------- // 作った数列に0が含まれないようにするときのDP long[][] dp1 = new long[n][3001]; // DPテーブルの1行目(a[0]ヶ所が1) for (int temp = 0; temp < a[0]; temp++) { dp1[0][temp] = 1; } // DPテーブルの2行目以降 for (int i = 1; i < n; i++) { for (int j = 0; j <= 3000; j++) { for (int temp = Math.max(0, j - a[i] + 1); temp <= j; temp++) { dp1[i][j] += dp1[i - 1][temp]; dp1[i][j] %= mod; } } } // ---------- // DP2回目 // ---------- // 作った数列に0が含まれるようにするときのDP long[][] dp2 = new long[n][3001]; // DPテーブルの1行目(1ヶ所だけが1) dp2[0][a[0]] = 1; // DPテーブルの2行目以降 for (int i = 1; i < n; i++) { for (int j = 0; j <= 3000; j++) { for (int temp = Math.max(0, j - a[i]); temp <= j; temp++) { dp2[i][j] += dp2[i - 1][temp]; dp2[i][j] %= mod; } if (0 <= j - a[i]) { dp2[i][j] += dp1[i - 1][j - a[i]]; dp2[i][j] %= mod; } } } // ---------- // 結果出力 // ---------- // DP1回目のテーブルより long result = dp1[n - 1][k]; // DP2回目のテーブルより for (int temp = 0; temp <= k; temp++) { result += dp2[n - 1][temp]; result %= mod; } // 出力 System.out.println(result); } // valを0にするには操作を何回すればいいかを求めて返す関数 static int getCnt(long val) { // 返却用 int ret = 0; // 0になるまで半減し続ける while (val != 0) { val /= 2; ret++; } return ret; } }
Submission Info
Submission Time | |
---|---|
Task | C - 半分 |
User | tobi00604 |
Language | Java (OpenJDK 11.0.6) |
Score | 500 |
Code Size | 2269 Byte |
Status | AC |
Exec Time | 371 ms |
Memory | 40596 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 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 | 371 ms | 39912 KiB |
02.txt | AC | 348 ms | 40088 KiB |
03.txt | AC | 334 ms | 40068 KiB |
04.txt | AC | 351 ms | 40340 KiB |
05.txt | AC | 339 ms | 40236 KiB |
06.txt | AC | 349 ms | 40356 KiB |
07.txt | AC | 350 ms | 40092 KiB |
08.txt | AC | 330 ms | 40036 KiB |
09.txt | AC | 353 ms | 40128 KiB |
10.txt | AC | 342 ms | 39968 KiB |
11.txt | AC | 336 ms | 40168 KiB |
12.txt | AC | 353 ms | 39952 KiB |
13.txt | AC | 96 ms | 35676 KiB |
14.txt | AC | 102 ms | 35732 KiB |
15.txt | AC | 124 ms | 36152 KiB |
16.txt | AC | 251 ms | 40320 KiB |
17.txt | AC | 249 ms | 40316 KiB |
18.txt | AC | 259 ms | 39888 KiB |
19.txt | AC | 247 ms | 40084 KiB |
20.txt | AC | 261 ms | 39996 KiB |
21.txt | AC | 250 ms | 40204 KiB |
22.txt | AC | 249 ms | 40068 KiB |
23.txt | AC | 260 ms | 40596 KiB |
24.txt | AC | 249 ms | 40172 KiB |
25.txt | AC | 241 ms | 40232 KiB |
26.txt | AC | 240 ms | 40348 KiB |
27.txt | AC | 244 ms | 40072 KiB |
28.txt | AC | 322 ms | 40184 KiB |
29.txt | AC | 314 ms | 39992 KiB |
30.txt | AC | 127 ms | 37492 KiB |
31.txt | AC | 177 ms | 39960 KiB |
32.txt | AC | 173 ms | 40340 KiB |
sample-01.txt | AC | 107 ms | 35580 KiB |
sample-02.txt | AC | 103 ms | 35452 KiB |
sample-03.txt | AC | 126 ms | 36816 KiB |
sample-04.txt | AC | 163 ms | 37864 KiB |