結果

問題 No.4 おもりと天秤
ユーザー iicafiaxus
提出日時 2016-08-29 23:06:25
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 565 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 131,148 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 03:50:27
合計ジャッジ時間 1,527 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

void main(){
	int n = readln.chomp.to!int;
	int[] ws = readln.chomp.split.map!(to!int).array;
	
	ws.sort!("a > b")();
	
	bool[] fs;
	fs.length = 10009;
	fs[0] = 1;
	
	foreach(w; ws){
		foreach_reverse(i; 0 .. 10009){
			if(i - w >= 0 && fs[i - w]) fs[i] = 1;
			}
		}
	
	string ans;
	int sum = ws.reduce!((a, b) => a + b);
	if(sum % 2 == 0 && fs[sum / 2]) ans = "possible";
	else ans = "impossible";
	
	ans.writeln;
	}
0