結果

問題 No.1017 Reiwa Sequence
ユーザー tentententen
提出日時 2022-08-30 15:36:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 573 ms / 2,000 ms
コード長 2,430 bytes
コンパイル時間 2,159 ms
コンパイル使用メモリ 78,760 KB
実行使用メモリ 117,656 KB
最終ジャッジ日時 2024-04-25 00:45:32
合計ジャッジ時間 43,478 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
36,568 KB
testcase_01 AC 46 ms
36,692 KB
testcase_02 AC 47 ms
37,032 KB
testcase_03 AC 48 ms
37,300 KB
testcase_04 AC 45 ms
36,568 KB
testcase_05 AC 44 ms
36,640 KB
testcase_06 AC 45 ms
36,648 KB
testcase_07 AC 51 ms
37,208 KB
testcase_08 AC 45 ms
36,908 KB
testcase_09 AC 49 ms
37,320 KB
testcase_10 AC 53 ms
39,520 KB
testcase_11 AC 50 ms
37,260 KB
testcase_12 AC 76 ms
56,156 KB
testcase_13 AC 64 ms
54,716 KB
testcase_14 AC 50 ms
37,384 KB
testcase_15 AC 54 ms
37,320 KB
testcase_16 AC 47 ms
36,916 KB
testcase_17 AC 68 ms
40,072 KB
testcase_18 AC 48 ms
37,340 KB
testcase_19 AC 373 ms
81,536 KB
testcase_20 AC 377 ms
81,704 KB
testcase_21 AC 377 ms
81,864 KB
testcase_22 AC 367 ms
81,844 KB
testcase_23 AC 397 ms
81,812 KB
testcase_24 AC 413 ms
81,532 KB
testcase_25 AC 373 ms
81,768 KB
testcase_26 AC 344 ms
81,352 KB
testcase_27 AC 264 ms
68,772 KB
testcase_28 AC 374 ms
78,544 KB
testcase_29 AC 80 ms
41,420 KB
testcase_30 AC 94 ms
45,728 KB
testcase_31 AC 127 ms
49,108 KB
testcase_32 AC 239 ms
68,648 KB
testcase_33 AC 74 ms
40,160 KB
testcase_34 AC 250 ms
68,728 KB
testcase_35 AC 48 ms
39,008 KB
testcase_36 AC 49 ms
38,976 KB
testcase_37 AC 232 ms
68,796 KB
testcase_38 AC 49 ms
39,124 KB
testcase_39 AC 259 ms
68,808 KB
testcase_40 AC 546 ms
115,196 KB
testcase_41 AC 540 ms
115,420 KB
testcase_42 AC 567 ms
115,420 KB
testcase_43 AC 568 ms
117,544 KB
testcase_44 AC 158 ms
59,828 KB
testcase_45 AC 573 ms
117,656 KB
testcase_46 AC 533 ms
115,456 KB
testcase_47 AC 509 ms
115,280 KB
testcase_48 AC 182 ms
61,580 KB
testcase_49 AC 181 ms
61,448 KB
testcase_50 AC 186 ms
60,988 KB
testcase_51 AC 46 ms
37,204 KB
testcase_52 AC 361 ms
81,316 KB
testcase_53 AC 144 ms
52,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int size = Math.min(22, n);
        int[] values = new int[size];
        for (int i = 0; i < size; i++) {
            values[i] = sc.nextInt();
        }
        int[] dp = new int[1 << size];
        HashMap<Integer, Integer> exist = new HashMap<>();
        for (int i = 1; i < (1 << size); i++) {
            for (int j = 0; j < size; j++) {
                if ((i & (1 << j)) == 0) {
                    continue;
                }
                dp[i] = dp[i ^ (1 << j)] + values[j];
                break;
            }
            if (exist.containsKey(dp[i])) {
                int x = exist.get(dp[i]);
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < size; j++) {
                    if (j > 0) {
                        sb.append(" ");
                    }
                    if ((x & (1 << j)) == 0 && (i & (1 << j)) != 0) {
                        sb.append(-values[j]);
                    } else if ((x & (1 << j)) != 0 && (i & (1 << j)) == 0) {
                        sb.append(values[j]);
                    } else {
                        sb.append("0");
                    }
                }
                for (int j = size; j < n; j++) {
                    sb.append(" 0");
                }
                System.out.println("Yes");
                System.out.println(sb);
                return;
            } else {
                exist.put(dp[i], i);
            }
        }
        System.out.println("No");
    }
}
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0