結果

問題 No.4 おもりと天秤
ユーザー kuramubonnkuramubonn
提出日時 2023-02-03 15:32:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 162 ms / 5,000 ms
コード長 844 bytes
コンパイル時間 5,023 ms
コンパイル使用メモリ 73,584 KB
実行使用メモリ 61,092 KB
最終ジャッジ日時 2023-09-15 11:08:44
合計ジャッジ時間 6,883 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
60,440 KB
testcase_01 AC 125 ms
56,092 KB
testcase_02 AC 148 ms
60,372 KB
testcase_03 AC 148 ms
60,452 KB
testcase_04 AC 147 ms
60,436 KB
testcase_05 AC 160 ms
60,704 KB
testcase_06 AC 147 ms
60,772 KB
testcase_07 AC 162 ms
60,448 KB
testcase_08 AC 134 ms
55,856 KB
testcase_09 AC 160 ms
60,548 KB
testcase_10 AC 159 ms
60,600 KB
testcase_11 AC 145 ms
60,340 KB
testcase_12 AC 147 ms
61,092 KB
testcase_13 AC 145 ms
60,368 KB
testcase_14 AC 147 ms
60,684 KB
testcase_15 AC 147 ms
60,116 KB
testcase_16 AC 147 ms
60,700 KB
testcase_17 AC 147 ms
60,144 KB
testcase_18 AC 159 ms
61,088 KB
testcase_19 AC 162 ms
60,432 KB
testcase_20 AC 159 ms
60,592 KB
testcase_21 AC 160 ms
60,928 KB
testcase_22 AC 161 ms
60,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] data = new int [sc.nextInt()];
		
		int num = 0;
		for(int i = 0 ; i < data.length ; i++) {
			data[i] = sc.nextInt();
			num += data[i];
		}
		
		if(num % 2 == 1) {
			System.out.println("impossible");
			return;
		}
		
		num /= 2;
		
		Boolean [][] flug = new Boolean [101][10001];
		
		for(int i = 0 ; i < 101 ; i++)
			for(int j = 0 ; j < 10001 ; j++)
				flug[i][j] = false;
		
		flug[0][0] = true;
		
		for(int i = 0 ; i < data.length ; i++) {
			for(int j = 0 ; j < 10000 ; j++) {
				if(flug[i][j] == true) {
					flug[i + 1][j + data[i]] = true;
					flug[i + 1][j] = true;
				}
			}
		}
		
		if(flug[data.length][num] == true)System.out.println("possible");
		else System.out.println("impossible");
	}
}
0