結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2017-03-01 02:30:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 577 bytes |
| コンパイル時間 | 1,432 ms |
| コンパイル使用メモリ | 168,004 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 10:09:52 |
| 合計ジャッジ時間 | 2,180 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
int N;
int W[100];
//-----------------------------------------------------------------
bool dp[101][10101];
int main() {
cin >> N;
rep(i, 0, N) cin >> W[i];
dp[0][0] = true;
rep(i, 0, N) rep(j, 0, 10101) if(dp[i][j]){
dp[i + 1][j] = true;
int jj = j + W[i];
if (jj <= 10000) dp[i + 1][jj] = true;
}
string ans = "impossible";
int sm = 0;
rep(i, 0, N) sm += W[i];
rep(j, 0, sm) {
int oth = sm - j;
if (dp[N][j] && j == oth) ans = "possible";
}
cout << ans << endl;
}
はまやんはまやん