結果
問題 | No.1731 Product of Subsequence |
ユーザー | tenten |
提出日時 | 2023-03-27 11:24:44 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,590 bytes |
コンパイル時間 | 3,054 ms |
コンパイル使用メモリ | 87,196 KB |
実行使用メモリ | 298,116 KB |
最終ジャッジ日時 | 2023-10-19 14:03:36 |
合計ジャッジ時間 | 15,640 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | AC | 58 ms
51,568 KB |
testcase_02 | AC | 58 ms
52,488 KB |
testcase_03 | AC | 58 ms
53,600 KB |
testcase_04 | AC | 58 ms
53,608 KB |
testcase_05 | AC | 65 ms
52,904 KB |
testcase_06 | AC | 70 ms
54,208 KB |
testcase_07 | AC | 59 ms
52,476 KB |
testcase_08 | AC | 165 ms
63,756 KB |
testcase_09 | WA | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | AC | 117 ms
55,876 KB |
testcase_13 | AC | 205 ms
64,412 KB |
testcase_14 | TLE | - |
testcase_15 | AC | 60 ms
53,616 KB |
testcase_16 | WA | - |
testcase_17 | AC | 58 ms
53,612 KB |
testcase_18 | TLE | - |
testcase_19 | AC | 206 ms
64,164 KB |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | AC | 110 ms
56,016 KB |
testcase_23 | WA | - |
testcase_24 | AC | 160 ms
60,828 KB |
testcase_25 | AC | 141 ms
59,944 KB |
testcase_26 | AC | 610 ms
105,288 KB |
testcase_27 | AC | 934 ms
118,012 KB |
testcase_28 | AC | 1,959 ms
169,432 KB |
testcase_29 | AC | 752 ms
110,320 KB |
testcase_30 | TLE | - |
testcase_31 | AC | 127 ms
56,096 KB |
testcase_32 | WA | - |
testcase_33 | AC | 123 ms
55,852 KB |
testcase_34 | AC | 392 ms
82,124 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static long[] values; static ArrayList<HashMap<Long, Integer>> dp = new ArrayList<>(); static final int MOD = 1000000007; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); long k = sc.nextLong(); values = new long[n]; for (int i = 0; i < n; i++) { values[i] = getGCD(sc.nextLong(), k); dp.add(new HashMap<>()); } System.out.println(dfw(n - 1, k)); } static int dfw(int idx, long v) { if (v == 1) { return pow(2, idx + 1); } if (idx < 0) { return 0; } if (!dp.get(idx).containsKey(v)) { dp.get(idx).put(v, (dfw(idx - 1, v) + dfw(idx - 1, v / getGCD(v, values[idx]))) % MOD); } return dp.get(idx).get(v); } static long getGCD(long x, long y) { if (y == 0) { return x; } else { return getGCD(y, x % y); } } static int pow(long x, int p) { if (p == 0) { return 1; } else if (p % 2 == 0) { return pow(x * x % MOD, p / 2); } else { return (int)(pow(x, p - 1) * (long)x % MOD); } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }