結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-04-13 23:27:46 | 
| 言語 | C (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,057 bytes | 
| コンパイル時間 | 574 ms | 
| コンパイル使用メモリ | 30,336 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-01 05:28:30 | 
| 合計ジャッジ時間 | 2,149 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 8 WA * 6 RE * 9 | 
ソースコード
/*
 * FileName:     code
 * CreatedDate:  2020-04-05 16:01:12 +0900
 * LastModified: 2020-04-13 23:26:45 +0900
 */
#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int w[n];
    int count=0,total;
    for(int i=0;i<n;i++){
        scanf("%d",&w[i]);
        count+=w[i];
    }
    if(count%2==1){
        printf("impossible\n");
        return 0;
    }
    total=count/2;
    
    int dp[n+1][total+1];
    for(int j=0;j<total+1;j++){
        dp[0][j]=0;
    }
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<total+1;j++){
            if(w[i]>j){
                dp[i+1][j]=dp[i][j];
            }
            else{
                if(dp[i][j-w[i]]==1||dp[i][j]==1){dp[i+1][j]=1;}
                else{dp[i+1][j]=0;}
            }
        }
    }
/*    for(int i=0;i<n+1;i++){
        for(int j=0;j<total+1;j++){
            printf("%d ",dp[i][j]);
        }
        printf("\n");
    }*/
    if(dp[n+1][total+1]==1){
        printf("possible\n");
        return 0;
    }
    printf("impossible\n");
    return 0;
}
            
            
            
        