結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-27 18:29:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 923 bytes |
| コンパイル時間 | 576 ms |
| コンパイル使用メモリ | 74,596 KB |
| 実行使用メモリ | 818,044 KB |
| 最終ジャッジ日時 | 2024-11-27 11:07:47 |
| 合計ジャッジ時間 | 17,159 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 MLE * 10 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
int N;
int W[101], sum[101];
vector<pii> dp[101];
string ans = "impossible";
int main(void) {
cin >> N;
dp[0].push_back(pii(0, 0));
for (int n = 1; n <= N; ++n) cin >> W[n];
sum[1] = accumulate(W + 1, W + N + 1, 0);
for (int n = 2; n <= N; ++n) {
sum[n] = sum[n - 1] - W[n - 1];
}
for (int n = 1; n <= N; ++n) {
for (size_t idx = 0U; idx < dp[n - 1].size(); ++idx) {
pii pre = dp[n - 1][idx];
if (abs(pre.first + W[n] - pre.second) <= sum[n]) dp[n].push_back(pii(pre.first + W[n], pre.second));
if (abs(pre.first - (pre.second + W[n])) <= sum[n]) dp[n].push_back(pii(pre.first, pre.second + W[n]));
}
}
for (size_t idx = 0U; idx < dp[N].size(); ++idx) {
if (dp[N][idx].first == dp[N][idx].second) ans = "possible";
}
cout << ans << endl;
return 0;
}