結果

問題 No.4 おもりと天秤
ユーザー GrenacheGrenache
提出日時 2015-07-01 10:57:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 190 ms / 5,000 ms
コード長 950 bytes
コンパイル時間 3,397 ms
コンパイル使用メモリ 73,112 KB
実行使用メモリ 58,340 KB
最終ジャッジ日時 2023-09-08 16:20:52
合計ジャッジ時間 7,742 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,776 KB
testcase_01 AC 121 ms
55,580 KB
testcase_02 AC 123 ms
55,928 KB
testcase_03 AC 121 ms
56,036 KB
testcase_04 AC 122 ms
55,784 KB
testcase_05 AC 176 ms
57,956 KB
testcase_06 AC 122 ms
55,740 KB
testcase_07 AC 174 ms
57,952 KB
testcase_08 AC 128 ms
55,628 KB
testcase_09 AC 134 ms
55,528 KB
testcase_10 AC 178 ms
58,008 KB
testcase_11 AC 122 ms
56,132 KB
testcase_12 AC 121 ms
56,008 KB
testcase_13 AC 121 ms
55,336 KB
testcase_14 AC 122 ms
56,352 KB
testcase_15 AC 121 ms
55,936 KB
testcase_16 AC 122 ms
56,140 KB
testcase_17 AC 120 ms
56,036 KB
testcase_18 AC 190 ms
57,944 KB
testcase_19 AC 175 ms
58,340 KB
testcase_20 AC 171 ms
58,324 KB
testcase_21 AC 171 ms
57,384 KB
testcase_22 AC 170 ms
58,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


public class Main_yukicoder4 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] w = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
        	w[i] = sc.nextInt();
        	sum += w[i];
        }

        boolean flag = false;
        if (sum % 2 == 0) {
        	Set<Integer> hs = new HashSet<Integer>();
        	
        	for (int i = 0; i < n; i++) {
        		for (int e : hs.toArray(new Integer[0])) {
        			hs.add(w[i] + e);
        		}
        		hs.add(w[i]);
        		
        		if (hs.contains(sum / 2)) {
        			flag = true;
        			break;
        		}
        	}
        }

        if (flag) {
        	System.out.println("possible");
        } else {
        	System.out.println("impossible");
        }
        
        sc.close();
    }
}
0