結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
suika_p
|
| 提出日時 | 2019-09-23 01:44:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 5,000 ms |
| コード長 | 1,588 bytes |
| コンパイル時間 | 1,386 ms |
| コンパイル使用メモリ | 169,488 KB |
| 実行使用メモリ | 7,808 KB |
| 最終ジャッジ日時 | 2024-09-19 04:05:31 |
| 合計ジャッジ時間 | 2,366 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
コンパイルメッセージ
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) {
| ^~~~
ソースコード
#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];
chmin(dp[i+1][j], 2LL);
dp[i+1][j] += dp[i][j];
chmin(dp[i+1][j], 2LL);
}
}
rep(i, MAX) {
if (dp[N][i] >= 1 && i * 2 == sum) {
cout << "possible" << endl;
return 0;
}
}
cout << "impossible" << endl;
return 0;
}
suika_p