結果

問題 No.4 おもりと天秤
ユーザー cwwcww
提出日時 2017-06-26 01:51:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 866 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 170,192 KB
実行使用メモリ 7,148 KB
最終ジャッジ日時 2023-09-08 17:31:48
合計ジャッジ時間 2,625 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,804 KB
testcase_01 AC 4 ms
6,804 KB
testcase_02 AC 5 ms
6,864 KB
testcase_03 AC 5 ms
7,032 KB
testcase_04 AC 4 ms
6,980 KB
testcase_05 AC 5 ms
7,036 KB
testcase_06 AC 5 ms
7,036 KB
testcase_07 AC 5 ms
6,820 KB
testcase_08 AC 4 ms
6,964 KB
testcase_09 AC 4 ms
7,072 KB
testcase_10 AC 6 ms
7,096 KB
testcase_11 AC 4 ms
6,976 KB
testcase_12 AC 5 ms
6,816 KB
testcase_13 AC 4 ms
6,816 KB
testcase_14 AC 4 ms
7,148 KB
testcase_15 AC 5 ms
6,812 KB
testcase_16 AC 5 ms
6,804 KB
testcase_17 AC 5 ms
6,836 KB
testcase_18 AC 6 ms
7,144 KB
testcase_19 AC 5 ms
6,892 KB
testcase_20 AC 5 ms
7,096 KB
testcase_21 AC 6 ms
7,056 KB
testcase_22 AC 6 ms
6,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
vector<vector<int>> memo( 100 + 1, vector<int>( 10000 + 1, -1 ) );
int N, total, res;
vector<int> vc;
bool dfs( int i, int x )
{
    if( i == 0 )
    {
        return x == 0;
    }
    if( x < 0 )
    {
        return false;
    }
    int &res = memo[ i ][ x ];
    if( res != -1 )
    {
        return res;
    }
    return ( res = dfs( i - 1, x ) || dfs( i - 1, x - vc[ i - 1 ] ) );
}
int main()
{
    cin >> N;
    vc.resize( N );
    for( auto &x : vc )
    {
        cin >> x;
    }
    total = accumulate( ALL( vc ), 0 );
    cout << ( dfs( N - 1, total / 2 ) && total % 2 == 0 ? "possible" : "impossible" ) << endl;
    return 0;
}
0