結果

問題 No.4 おもりと天秤
ユーザー tmsausa
提出日時 2018-04-12 19:33:16
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 632 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 30,080 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-26 21:32:52
合計ジャッジ時間 1,168 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>

int main(void){
    int N;
    scanf("%d\n",&N);
    int weights[101]={0};
    int j;
    int i;
    for(;j<N;j++){
        scanf("%d",&(weights[j+1]));
    }
    int sum=0;
    for(j=0;j<N+1;j++)sum+=weights[j];
    if(sum%2==1){
        printf("impossible\n");
        return 0;
    }
    int dp[101][10001];
    dp[0][0] = 1;
    for(i=1;i<N+1;i++)
    for(j=0;j<10001;j++){
        if ((dp[i-1][j] == 1) || ((j >= weights[i]) && (dp[i-1][j-weights[i]] == 1))){
            dp[i][j] = 1;
        }
    }
    if(dp[N][sum/2]){
        printf("possible\n");
    }
    else{
        printf("impossible");
    }

}
0