結果

問題 No.4 おもりと天秤
ユーザー 小指が強い人
提出日時 2016-01-04 09:43:52
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 607 bytes
コンパイル時間 517 ms
コンパイル使用メモリ 59,604 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 09:22:50
合計ジャッジ時間 1,351 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
int n;
vector<int> w;
bool memo[100][10005] = {0};
bool solve(int i, int wi, int wj)
{
    if(i >= n)
        return wi == wj;
    if(memo[i][wi])
        return false;
    memo[i][wi] = true;
    if(solve(i + 1, wi + w[i], wj))
        return true;
    if(solve(i + 1, wi, wj + w[i]))
        return true;
    return false;
}
int main(void)
{
    cin >> n;
    w.resize(n);
    for(int i = 0; i < n; i++)
        cin >> w[i];
    if(solve(0, 0, 0))
        cout << "possible" << endl;
    else
        cout << "impossible" << endl;
    return 0;
}
0