結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
core123
|
| 提出日時 | 2019-04-17 14:33:28 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 237 ms / 5,000 ms |
| コード長 | 1,276 bytes |
| コンパイル時間 | 2,457 ms |
| コンパイル使用メモリ | 79,792 KB |
| 実行使用メモリ | 57,524 KB |
| 最終ジャッジ日時 | 2024-09-22 08:30:15 |
| 合計ジャッジ時間 | 7,349 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
import java.util.*;
import java.util.stream.*;
import static java.lang.Math.*;
public class Main{
public static void main(String... args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] w=new int[n];
for(int i=0;i<n;i++){
w[i]=sc.nextInt();
}
int wSum=0;
Set<Integer> set=new HashSet<>();
set.add(0);
for(int i=0;i<n;i++){
wSum+=w[i];
List<Integer> list=new ArrayList<>(set);
for(int x:list){
set.add(x+w[i]);
}
}
if(wSum%2==1){
put("impossible");
return;
}
if(set.contains(wSum/2)){
put("possible");
}else{
put("impossible");
}
}
public static class Pair{
final int x,y;
Pair(int x,int y){
this.x=x;
this.y=y;
}
@Override
public String toString(){
return String.format("Pair(%d,%d)",x,y);
}
}
public static void print(Object object){
System.out.print(object);
}
public static void put(Object object) {
System.out.println(object);
}
public static void put(){
System.out.println();
}
public static void print(String format,Object... args){
System.out.print(String.format(format,args));
}
public static void put(String format,Object... args) {
System.out.println(String.format(format,args));
}
}
core123