結果
| 問題 | No.4 おもりと天秤 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-12-16 12:30:19 |
| 言語 | C++11 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 757 bytes |
| 記録 | |
| コンパイル時間 | 337 ms |
| コンパイル使用メモリ | 82,772 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-08-28 13:10:07 |
| 合計ジャッジ時間 | 7,388 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 2 TLE * 1 -- * 17 |
ソースコード
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int n;
const int N=100;
vector<int> w(N);
int sum=0;
int dp[101][5001];
//x番目に注目していて、現在の重さはy
int rec(int x, int y){
if(x==n) return (y==sum/2);
if(dp[x][y]>=0) return dp[x][y];
int ret;
if(y+w[x]>sum/2) ret = rec(x+1,y);
else ret = rec(x+1,y) || rec(x+1, y+w[x]);
return ret;
}
int main(int argc, char const *argv[]) {
cin >>n;
for(int i=0; i<n; ++i){
scanf(" %d", &w[i]);
sum += w[i];
}
memset(dp, -1, sizeof(dp));
if(sum%2==0){
int ret=rec(0, 0);
if(ret==1) printf("possible\n");
else printf("impposible\n");
}
else printf("impposible\n");
return 0;
}