結果

問題 No.1017 Reiwa Sequence
ユーザー tentententen
提出日時 2023-02-01 11:42:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,667 ms / 2,000 ms
コード長 2,945 bytes
コンパイル時間 2,586 ms
コンパイル使用メモリ 92,548 KB
実行使用メモリ 253,744 KB
最終ジャッジ日時 2023-09-14 00:16:38
合計ジャッジ時間 48,391 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
50,768 KB
testcase_01 AC 45 ms
47,452 KB
testcase_02 AC 57 ms
50,680 KB
testcase_03 AC 62 ms
50,832 KB
testcase_04 AC 59 ms
50,788 KB
testcase_05 AC 59 ms
50,948 KB
testcase_06 AC 57 ms
50,748 KB
testcase_07 AC 59 ms
50,668 KB
testcase_08 AC 60 ms
50,720 KB
testcase_09 AC 70 ms
51,656 KB
testcase_10 AC 96 ms
54,388 KB
testcase_11 AC 72 ms
52,828 KB
testcase_12 AC 108 ms
56,352 KB
testcase_13 AC 65 ms
51,428 KB
testcase_14 AC 63 ms
51,968 KB
testcase_15 AC 83 ms
52,408 KB
testcase_16 AC 63 ms
51,696 KB
testcase_17 AC 109 ms
57,864 KB
testcase_18 AC 62 ms
51,960 KB
testcase_19 AC 1,365 ms
198,884 KB
testcase_20 AC 1,365 ms
198,992 KB
testcase_21 AC 1,355 ms
199,456 KB
testcase_22 AC 1,334 ms
197,196 KB
testcase_23 AC 1,331 ms
199,440 KB
testcase_24 AC 1,345 ms
196,340 KB
testcase_25 AC 1,330 ms
199,036 KB
testcase_26 AC 1,212 ms
199,148 KB
testcase_27 AC 886 ms
167,328 KB
testcase_28 AC 1,067 ms
194,400 KB
testcase_29 AC 140 ms
59,408 KB
testcase_30 AC 164 ms
62,512 KB
testcase_31 AC 268 ms
73,444 KB
testcase_32 AC 709 ms
128,108 KB
testcase_33 AC 109 ms
56,648 KB
testcase_34 AC 735 ms
129,760 KB
testcase_35 AC 58 ms
48,644 KB
testcase_36 AC 63 ms
50,828 KB
testcase_37 AC 720 ms
128,336 KB
testcase_38 AC 59 ms
50,768 KB
testcase_39 AC 725 ms
128,388 KB
testcase_40 AC 1,667 ms
251,392 KB
testcase_41 AC 1,522 ms
252,820 KB
testcase_42 AC 1,542 ms
246,832 KB
testcase_43 AC 1,531 ms
251,488 KB
testcase_44 AC 191 ms
62,088 KB
testcase_45 AC 1,528 ms
253,744 KB
testcase_46 AC 1,480 ms
246,720 KB
testcase_47 AC 1,475 ms
253,232 KB
testcase_48 AC 247 ms
64,296 KB
testcase_49 AC 232 ms
63,912 KB
testcase_50 AC 252 ms
66,320 KB
testcase_51 AC 44 ms
49,396 KB
testcase_52 AC 1,304 ms
197,844 KB
testcase_53 AC 379 ms
91,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0