結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2018-01-10 11:25:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 733 bytes |
コンパイル時間 | 634 ms |
コンパイル使用メモリ | 68,008 KB |
実行使用メモリ | 6,816 KB |
最終ジャッジ日時 | 2024-12-23 15:36:16 |
合計ジャッジ時間 | 1,590 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 WA * 1 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:33:22: warning: iteration 10010 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[110][10010] = {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"; return 0; }