結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2020-04-13 23:30:22 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 1,053 bytes |
コンパイル時間 | 384 ms |
コンパイル使用メモリ | 30,592 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-01 05:30:14 |
合計ジャッジ時間 | 1,215 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
/* * 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; }