結果

問題 No.4 おもりと天秤
ユーザー NaruY
提出日時 2016-10-24 01:25:51
言語 Java
(openjdk 23)
結果
AC  
実行時間 147 ms / 5,000 ms
コード長 1,016 bytes
コンパイル時間 2,118 ms
コンパイル使用メモリ 78,488 KB
実行使用メモリ 41,752 KB
最終ジャッジ日時 2024-06-26 10:02:31
合計ジャッジ時間 5,967 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
 
public class Main {
    public static void main (String[] args) throws IOException
    {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	
    	int w[] = new int [N+1];
    	boolean c[] = new boolean [10001];
    	c[0] = true;
    	int m = 0;
    	
    	
    	for (int i = 1 ; i <= N ; i++){
    		w[i] = sc.nextInt();
    		m += w[i];
    	}
    	
    	if (m % 2 == 1){
    		System.out.println("impossible");
    	} else
    	{              
    	
    	  for(int i = 1 ; i <= N ; i++){
    		  for(int j = m/2 ; j >= 0 ; j--){
    			if (c[j]) {
    				c[j + w[i]] = true;
    			}    			
    		  }
    	  }
    		
    	  if (c[m/2]){
    		  System.out.println("possible");
    	  }else{
    		  System.out.println("impossible");
    	  }
    	  
    	  
    	}
    	
    	
    	
    	
    }	
}
    
   
0