結果

問題 No.4 おもりと天秤
ユーザー BucchimanBucchiman
提出日時 2020-04-13 23:27:46
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,057 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 30,720 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-08 11:34:24
合計ジャッジ時間 2,415 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
6,548 KB
testcase_02 RE -
testcase_03 WA -
testcase_04 RE -
testcase_05 RE -
testcase_06 WA -
testcase_07 RE -
testcase_08 AC 1 ms
6,548 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 1 ms
6,548 KB
testcase_12 AC 1 ms
6,548 KB
testcase_13 AC 1 ms
6,548 KB
testcase_14 AC 1 ms
6,548 KB
testcase_15 AC 1 ms
6,548 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
 * 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;
}
0