結果
問題 | No.917 Make One With GCD |
ユーザー | htensai |
提出日時 | 2019-12-18 15:57:12 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,455 bytes |
コンパイル時間 | 3,586 ms |
コンパイル使用メモリ | 75,168 KB |
実行使用メモリ | 53,088 KB |
最終ジャッジ日時 | 2023-09-20 18:18:22 |
合計ジャッジ時間 | 5,423 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
34,108 KB |
testcase_01 | AC | 41 ms
33,468 KB |
testcase_02 | AC | 41 ms
33,580 KB |
testcase_03 | AC | 44 ms
33,484 KB |
testcase_04 | AC | 41 ms
33,460 KB |
testcase_05 | AC | 41 ms
33,500 KB |
testcase_06 | AC | 42 ms
33,404 KB |
testcase_07 | AC | 42 ms
33,492 KB |
testcase_08 | AC | 44 ms
33,928 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 42 ms
33,376 KB |
testcase_18 | WA | - |
testcase_19 | AC | 41 ms
33,484 KB |
testcase_20 | AC | 41 ms
33,832 KB |
testcase_21 | AC | 43 ms
33,772 KB |
testcase_22 | AC | 42 ms
33,340 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 42 ms
33,484 KB |
testcase_27 | AC | 41 ms
33,424 KB |
testcase_28 | AC | 40 ms
33,408 KB |
testcase_29 | AC | 40 ms
33,540 KB |
testcase_30 | AC | 40 ms
33,452 KB |
testcase_31 | AC | 40 ms
33,472 KB |
testcase_32 | AC | 41 ms
33,564 KB |
testcase_33 | AC | 40 ms
33,524 KB |
testcase_34 | AC | 40 ms
33,632 KB |
testcase_35 | AC | 40 ms
33,564 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { static HashMap<Integer, Long>[] maps; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] first = br.readLine().split(" ", n); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(first[i]); } maps = new HashMap[n]; for (int i = 0; i < n; i++) { maps[i] = new HashMap<Integer, Long>(); } System.out.println(getCount(0, arr, -1)); } static long getCount(int idx, int[] arr, int value) { if (idx >= arr.length) { return 0; } if (maps[idx].containsKey(value)) { return maps[idx].get(value); } long count = getCount(idx + 1, arr, value); if (value == -1) { value = arr[idx]; } else { value = gcd(value, arr[idx]); } if (value == 1) { count += (long)(Math.pow(2, arr.length - idx - 1)); } else { count += getCount(idx + 1, arr, value); } maps[idx].put(value, count); return count; } static int gcd(int x, int y) { if (x % y == 0) { return y; } else { return gcd(y, x % y); } } }