結果

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

テストケース

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

ソースコード

diff #

/*
 * FileName:     code
 * CreatedDate:  2020-04-05 16:01:12 +0900
 * LastModified: 2020-04-13 23:29:59 +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][total]==1){
        printf("possible\n");
        return 0;
    }
    printf("impossible\n");
    return 0;
}
0