結果
問題 | No.4 おもりと天秤 |
ユーザー |
![]() |
提出日時 | 2018-01-10 11:23:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 718 bytes |
コンパイル時間 | 802 ms |
コンパイル使用メモリ | 67,764 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-23 15:36:14 |
合計ジャッジ時間 | 3,301 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 WA * 1 RE * 9 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:33:22: warning: iteration 10001 invokes undefined behavior [-Waggressive-loop-optimizations] 33 | if(dp[i][j]) | ~~~~~~~^ main.cpp:31:25: note: within this loop 31 | for(int j = 0; j <= 100000; j++) | ~~^~~~~~~~~
ソースコード
#include <iostream> #include <algorithm> #include <cstring> using namespace std; int N, sum = 0; int w[110]; bool dp[101][10001] = {false}; int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> w[i]; sum += w[i]; } dp[0][0] = true; if (sum % 2 == 1) { cout << "impossible" << endl; return 0; } int m = sum / 2; for(int i = 0; i < N; i++) { for(int j = 0; j <= 100000; j++) { if(dp[i][j]) { dp[i + 1][j + w[i]] = true; dp[i + 1][j] = true; } } } if(dp[N][sum / 2]) cout << "possible\n"; else cout << "impossible\n"; }