結果

問題 No.4 おもりと天秤
ユーザー pianoneko
提出日時 2018-08-31 14:52:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 2,211 bytes
コンパイル時間 1,041 ms
コンパイル使用メモリ 116,260 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-13 22:33:39
合計ジャッジ時間 1,995 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>

/* 
PascalCase  クラス名
camelCase   メソッド名,関数名,変数名
snake_case  ファイル名,名前空間,std のメソッド名,変数名,型名に準じる場合
SNAKE_CASE	マクロ名,static const 定数,列挙体
*/

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define Cout(obj) cout << obj << endl
#define Size(obj) (int)(obj).size()
#define fcout cout << fixed << setprecision(10)
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

bool dp[110][10010];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    vector<int> W(N);
    REP(i, N)
    {
        cin >> W[i];
    }

    int sum = accumulate(ALL(W), 0);

    memset(dp, false, sizeof(dp));

    dp[0][0] = true;

    if(sum % 2 == 1)
    {
        Cout("impossible");
    }    
    else
    {
        REP(i, N)
        {
            REP(j, sum + 1)
            {
                if(dp[i][j] == false) continue;

                dp[i + 1][j + W[i]] = true;
                dp[i + 1][j] = true;
            }
        }

        Cout((dp[N][sum / 2] ? "possible" : "impossible"));

    }


    return 0;
}
0