結果

問題 No.4 おもりと天秤
ユーザー suika_psuika_p
提出日時 2019-09-23 00:32:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 1,528 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 169,596 KB
実行使用メモリ 75,664 KB
最終ジャッジ日時 2023-10-19 07:29:37
合計ジャッジ時間 2,889 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,740 KB
testcase_01 AC 4 ms
7,740 KB
testcase_02 AC 7 ms
15,932 KB
testcase_03 AC 5 ms
11,836 KB
testcase_04 AC 6 ms
15,932 KB
testcase_05 AC 28 ms
64,016 KB
testcase_06 AC 3 ms
5,692 KB
testcase_07 AC 29 ms
67,912 KB
testcase_08 AC 27 ms
65,172 KB
testcase_09 AC 28 ms
10,012 KB
testcase_10 AC 29 ms
66,064 KB
testcase_11 AC 5 ms
9,788 KB
testcase_12 AC 3 ms
7,740 KB
testcase_13 AC 3 ms
7,740 KB
testcase_14 AC 4 ms
7,740 KB
testcase_15 AC 4 ms
7,740 KB
testcase_16 AC 4 ms
11,836 KB
testcase_17 AC 4 ms
9,788 KB
testcase_18 AC 27 ms
75,664 KB
testcase_19 AC 29 ms
73,708 KB
testcase_20 AC 29 ms
71,724 KB
testcase_21 AC 29 ms
71,720 KB
testcase_22 AC 29 ms
71,732 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:41:24: warning: iteration 100010 invokes undefined behavior [-Waggressive-loop-optimizations]
   41 |             if (dp[i][j] == 0) continue;
      |                 ~~~~~~~^
main.cpp:7:38: note: within this loop
    7 | #define reps(i, n) for (int i = 0; i <= (int)(n); i++)
      |                                      ^
main.cpp:40:9: note: in expansion of macro 'reps'
   40 |         reps(j, MAX) {
      |         ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


ll dp[110][100010];
const int MAX = 100010;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<ll> W(N); 
    int sum = 0;
    rep(i, N) {
        cin >> W[i];
        sum += W[i];
    }

    dp[0][0] = 1;

    rep(i, N) {
        reps(j, MAX) {
            if (dp[i][j] == 0) continue;
            dp[i+1][j+W[i]] += dp[i][j] % mod;
            dp[i+1][j] += dp[i][j] % mod;
        }
    }
    rep(i, MAX) {
        if (dp[N][i] >= 2 && i * 2 == sum) {
            cout << "possible" << endl;
            return 0;
        }
    }
    cout << "impossible" << endl;
    return 0;
}
0