結果

問題 No.4 おもりと天秤
ユーザー minato
提出日時 2019-12-26 17:41:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,023 bytes
コンパイル時間 1,963 ms
コンパイル使用メモリ 178,172 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-04 14:22:45
合計ジャッジ時間 2,427 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////
bool A[101][21000];
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> W(N);
    rep(i,N) cin >> W[i];

    A[0][10100] = true;
    rep(i,N) {
        rep(j,21000) {
            if (j >= W[i] && A[i][j]) A[i+1][j-W[i]] = true;
            if (j < 21000 - W[i] && A[i][j]) A[i+1][j+W[i]] = true;
        }
    }

    cout << (A[N][10100] ? "possible" : "impossible ") << endl;
}
0