結果
問題 | No.1017 Reiwa Sequence |
ユーザー | tenten |
提出日時 | 2023-02-01 11:42:05 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,731 ms / 2,000 ms |
コード長 | 2,945 bytes |
コンパイル時間 | 2,697 ms |
コンパイル使用メモリ | 91,940 KB |
実行使用メモリ | 244,604 KB |
最終ジャッジ日時 | 2024-07-01 08:13:47 |
合計ジャッジ時間 | 68,970 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 65 ms
38,144 KB |
testcase_01 | AC | 53 ms
37,184 KB |
testcase_02 | AC | 64 ms
37,784 KB |
testcase_03 | AC | 68 ms
37,916 KB |
testcase_04 | AC | 65 ms
37,656 KB |
testcase_05 | AC | 66 ms
37,712 KB |
testcase_06 | AC | 65 ms
37,572 KB |
testcase_07 | AC | 65 ms
37,912 KB |
testcase_08 | AC | 68 ms
37,724 KB |
testcase_09 | AC | 79 ms
38,616 KB |
testcase_10 | AC | 100 ms
41,424 KB |
testcase_11 | AC | 80 ms
38,928 KB |
testcase_12 | AC | 112 ms
42,160 KB |
testcase_13 | AC | 71 ms
38,376 KB |
testcase_14 | AC | 68 ms
38,448 KB |
testcase_15 | AC | 88 ms
40,036 KB |
testcase_16 | AC | 66 ms
38,492 KB |
testcase_17 | AC | 109 ms
46,120 KB |
testcase_18 | AC | 64 ms
38,376 KB |
testcase_19 | AC | 1,466 ms
186,764 KB |
testcase_20 | AC | 1,422 ms
189,992 KB |
testcase_21 | AC | 1,454 ms
188,760 KB |
testcase_22 | AC | 1,379 ms
188,776 KB |
testcase_23 | AC | 1,364 ms
188,740 KB |
testcase_24 | AC | 1,372 ms
187,600 KB |
testcase_25 | AC | 1,362 ms
188,608 KB |
testcase_26 | AC | 1,256 ms
188,188 KB |
testcase_27 | AC | 937 ms
156,700 KB |
testcase_28 | AC | 1,172 ms
186,788 KB |
testcase_29 | AC | 132 ms
48,448 KB |
testcase_30 | AC | 162 ms
49,888 KB |
testcase_31 | AC | 279 ms
61,488 KB |
testcase_32 | AC | 723 ms
118,028 KB |
testcase_33 | AC | 114 ms
42,724 KB |
testcase_34 | AC | 738 ms
116,304 KB |
testcase_35 | AC | 63 ms
37,716 KB |
testcase_36 | AC | 67 ms
38,140 KB |
testcase_37 | AC | 716 ms
116,048 KB |
testcase_38 | AC | 65 ms
37,756 KB |
testcase_39 | AC | 723 ms
115,992 KB |
testcase_40 | AC | 1,731 ms
243,456 KB |
testcase_41 | AC | 1,680 ms
244,604 KB |
testcase_42 | AC | 1,705 ms
243,288 KB |
testcase_43 | AC | 1,654 ms
243,796 KB |
testcase_44 | AC | 189 ms
50,372 KB |
testcase_45 | AC | 1,659 ms
243,344 KB |
testcase_46 | AC | 1,597 ms
243,700 KB |
testcase_47 | AC | 1,566 ms
243,460 KB |
testcase_48 | AC | 258 ms
53,060 KB |
testcase_49 | AC | 254 ms
54,220 KB |
testcase_50 | AC | 262 ms
54,728 KB |
testcase_51 | AC | 53 ms
37,240 KB |
testcase_52 | AC | 1,484 ms
189,108 KB |
testcase_53 | AC | 392 ms
79,472 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int length = Math.min(n, 30); int[] values = new int[length]; for (int i = 0; i < length; i++) { values[i] = sc.nextInt(); } HashMap<Integer, HashSet<Integer>> exist = new HashMap<>(); int[] ans = new int[n]; for (int i = 1; i < (1 << length); i++) { int sum = 0; for (int j = 0; j < length; j++) { if ((i & (1 << j)) == 0) { continue; } sum += values[j]; } if (!exist.containsKey(sum)) { exist.put(sum, new HashSet<>()); } for (int x : exist.get(sum)) { if ((i & x) == 0) { for (int j = 0; j < length; j++) { if ((x & (1 << j)) == 0) { continue; } ans[j] = values[j]; } for (int j = 0; j < length; j++) { if ((i & (1 << j)) == 0) { continue; } ans[j] = -values[j]; } System.out.println("Yes"); System.out.println(String.join(" ", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new))); return; } } exist.get(sum).add(i); } System.out.println("No"); } } 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(); } }