結果

問題 No.4 おもりと天秤
ユーザー y_taira_cy_taira_c
提出日時 2017-07-25 22:59:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,419 bytes
コンパイル時間 1,779 ms
コンパイル使用メモリ 167,300 KB
実行使用メモリ 10,144 KB
最終ジャッジ日時 2024-04-17 23:37:07
合計ジャッジ時間 8,407 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;


typedef int32_t h_int32;
typedef int64_t h_int64;
typedef uint32_t uh_int32;
typedef uint64_t uh_int64;
typedef h_int64 h_int;

#define REP( i, n ) for(int i = 0; i < ( int )( n ); ++i )
#define REPR( i, n ) for(int i = ( int )( n ); i >= 0; --i )
#define FOR( i, a, n ) for(int i = ( int )( a ); i < ( int )( n ); ++i )
#define FORR( i, a, n ) for(int i = ( int )( n ); i >= ( int )( a ); --i)

#define ALL( x ) x.begin(), x.end()

#define DOUT( x ) cerr << #x << " = " << x << "\n"
#define COUT( x ) cout << ( x ) << "\n"
#define DOUBLECOUT( num, x ) cout << fixed << setprecision( num ) << ( x ) << "\n"

#define INF 999999999
#define PI 3.14159265359

int n;
vector<int> v;
vector<int> vm;

bool f( int i, int left, int right )
{
        if( min( left, right ) + vm[i] < max( left, right ) ) return false;
        if(i == n) return left == right;
        if( f( i + 1, left + v[i], right ) ) return true;
        if( f( i + 1, left, right + v[i] ) ) return true;
        return false;
}

signed main()
{
        ios::sync_with_stdio( false );
        cin.tie( 0 );

        cin >> n;
        v.resize( n );
        vm.resize( n, 0 );
        REP( i, n )
        {
                cin >> v[i];
                vm[0] += v[i];
        }
        FOR( i, 1, n ) vm[i] = vm[i - 1] - v[i - 1];

        COUT( f( 0, 0, 0 ) ? "possible" : "impossible" );
        return 0;
}
0