結果

問題 No.4 おもりと天秤
ユーザー NrKmDevNrKmDev
提出日時 2020-03-27 17:49:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,417 bytes
コンパイル時間 1,388 ms
コンパイル使用メモリ 166,456 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2023-08-30 16:37:52
合計ジャッジ時間 2,534 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,848 KB
testcase_01 AC 3 ms
7,708 KB
testcase_02 AC 4 ms
7,668 KB
testcase_03 AC 3 ms
7,700 KB
testcase_04 AC 4 ms
7,640 KB
testcase_05 AC 4 ms
7,732 KB
testcase_06 AC 4 ms
7,972 KB
testcase_07 AC 4 ms
7,676 KB
testcase_08 AC 4 ms
7,724 KB
testcase_09 AC 4 ms
7,652 KB
testcase_10 AC 4 ms
7,836 KB
testcase_11 AC 4 ms
7,712 KB
testcase_12 AC 3 ms
7,796 KB
testcase_13 AC 3 ms
7,676 KB
testcase_14 AC 3 ms
7,948 KB
testcase_15 AC 4 ms
7,724 KB
testcase_16 AC 3 ms
7,784 KB
testcase_17 AC 4 ms
7,716 KB
testcase_18 AC 4 ms
7,680 KB
testcase_19 AC 5 ms
7,720 KB
testcase_20 AC 4 ms
7,668 KB
testcase_21 AC 4 ms
7,708 KB
testcase_22 AC 5 ms
7,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド:(典型)dp,dfs,bfs,最短経路,その他
ll dp[110][5010];
int main(){
    int n;cin >> n;
    vl w(n);
    rep(i,n) cin >> w[i];
    rep(i,110){
        rep(j,5010){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    rrep(i,n){
        rep(j,5001){
            if(j-w[i-1]>=0){
                if(dp[i-1][j-w[i-1]]!=INF){
                    dp[i][j]=dp[i-1][j-w[i-1]];
                }
            }
            if(dp[i-1][j]!=INF) dp[i][j]=dp[i-1][j]+w[i-1];
        }
    }
    //cout << dp[1][1] << endl;
    rep(j,5001){
        if(j==dp[n][j]){
            cout << "possible" << endl;
            return 0;
        } 
    }
    cout << "impossible" << endl;
    return 0;
}
0