結果

問題 No.4 おもりと天秤
ユーザー d2verbd2verb
提出日時 2015-05-05 11:18:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,102 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 81,152 KB
実行使用メモリ 7,576 KB
最終ジャッジ日時 2023-09-08 16:15:41
合計ジャッジ時間 1,533 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,276 KB
testcase_01 AC 5 ms
7,420 KB
testcase_02 AC 4 ms
7,424 KB
testcase_03 AC 5 ms
7,576 KB
testcase_04 AC 5 ms
7,288 KB
testcase_05 AC 5 ms
7,288 KB
testcase_06 AC 4 ms
7,280 KB
testcase_07 AC 5 ms
7,356 KB
testcase_08 AC 4 ms
7,276 KB
testcase_09 AC 4 ms
7,456 KB
testcase_10 AC 6 ms
7,364 KB
testcase_11 AC 4 ms
7,532 KB
testcase_12 AC 4 ms
7,280 KB
testcase_13 AC 5 ms
7,320 KB
testcase_14 AC 5 ms
7,292 KB
testcase_15 AC 4 ms
7,340 KB
testcase_16 AC 4 ms
7,356 KB
testcase_17 AC 4 ms
7,352 KB
testcase_18 AC 7 ms
7,424 KB
testcase_19 AC 5 ms
7,288 KB
testcase_20 AC 6 ms
7,344 KB
testcase_21 AC 5 ms
7,288 KB
testcase_22 AC 5 ms
7,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>

using namespace std;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)

typedef long long ll;
typedef unsigned long long ull;

int memo[101][10001], W[100], N;

void init(){
    for(int i = 0; i <= 100; i++){
        for(int j = 0; j <= 10000; j++){
            memo[i][j] = -1;
        }
    }
}

bool judge(int i, int left, int right){
    if(memo[i][left] >= 0) return (bool)memo[i][left];
    if(i == N) return left == right;
    
    return memo[i][left] = judge(i + 1, left + W[i], right) || judge(i + 1, left, right + W[i]);
}

int main(){
    ios_base::sync_with_stdio(0);
    init();
    cin >> N;
    for(int i = 0; i < N; i++) cin >> W[i];
    if(judge(0, 0, 0)) cout << "possible" << endl;
    else cout << "impossible" << endl;
    return 0;
}
0