結果

問題 No.4 おもりと天秤
ユーザー shinwisteriashinwisteria
提出日時 2017-03-26 19:30:41
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,027 bytes
コンパイル時間 3,577 ms
コンパイル使用メモリ 75,756 KB
実行使用メモリ 56,744 KB
最終ジャッジ日時 2023-09-20 11:06:15
合計ジャッジ時間 7,588 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,236 KB
testcase_01 AC 122 ms
55,936 KB
testcase_02 AC 124 ms
56,036 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 121 ms
56,312 KB
testcase_07 WA -
testcase_08 AC 131 ms
55,692 KB
testcase_09 AC 132 ms
56,012 KB
testcase_10 AC 131 ms
55,964 KB
testcase_11 AC 121 ms
56,240 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 122 ms
56,168 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 119 ms
55,796 KB
testcase_18 AC 128 ms
55,880 KB
testcase_19 AC 128 ms
56,364 KB
testcase_20 AC 128 ms
56,444 KB
testcase_21 AC 127 ms
56,480 KB
testcase_22 AC 129 ms
56,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class OmoritoTenbin {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt(),rest = 0;
		int[][] W = new int[N][2];
		for(int i = 0;i < N ;i++){
			W[i][0] = s.nextInt();
			rest += W[i][0];
			W[i][1] = 1;
		}
		s.close();
		if(rest%2 == 1){
			System.out.println("impossible");
		}else{
			rest /=2;
			int near = rest,k = 0;
			for(int i = 0;i < N;i++){
				if(W[i][1] != 0 &&Math.abs(near) > Math.abs(rest - W[i][0])){
					near = rest - W[i][0];
					k = i;
				}
				rest = Math.abs(near);
				W[k][1] = 0;
			}
			if(near == 0){
				System.out.println("possible");
			}else if(near < 0){
				for(int i = 0;i < N;i++){
					if(W[i][1] == 0){
						for(int j = i+1;j<N;j++){
							if(W[i][1] == 1 &&(W[i][0]+near == W[j][0] ||W[i][0] == near + W[j][0])){
								near = 0;
								break;
							}
						}
					}
					if(near == 0){
						break;
					}
				}
				if(near != 0){
					System.out.println("impossible");
				}
			}			
		}
	}
}
0