結果

問題 No.4 おもりと天秤
ユーザー nxterunxteru
提出日時 2017-06-06 23:42:30
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 596 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 29,564 KB
実行使用メモリ 4,976 KB
最終ジャッジ日時 2023-10-23 18:01:41
合計ジャッジ時間 1,040 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
int n,w[100],dp[100][10000];
int op(int i,int v){
    if(v<0){
        return -1;
    }
    if(dp[i][v]==0){
        if(i==n)
        dp[i][v]=v?-1:1;
        else{
            if(op(i+1,v)==1)
            dp[i][v]=1;
            
            if(op(i+1,v-2*w[i])==1)
            dp[i][v]=1;
             
             if(dp[i][v]==0)
             dp[i][v]=-1;
        
        }
    }
    return dp[i][v];
    
}
int main(void){
   scanf("%d",&n);
   int i,x=0;
   for(i=0;i<n;i++){
       scanf("%d",&w[i]);
       x+=w[i];
   }
   puts(op(0,x)==1?"possible":"impossible");
}
0