結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
Ronlynes
|
| 提出日時 | 2017-02-09 17:15:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 805 bytes |
| コンパイル時間 | 1,226 ms |
| コンパイル使用メモリ | 54,904 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-26 02:05:02 |
| 合計ジャッジ時間 | 1,513 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:27: warning: iteration 1005 invokes undefined behavior [-Waggressive-loop-optimizations]
25 | if(dp[i][j] == true){
| ~~~~~~~^
main.cpp:24:26: note: within this loop
24 | for(int j=0;j<=10000;j++){
| ~^~~~~~~
ソースコード
#include <iostream>
using namespace std;
int main(void){
int n,w[1005], sum = 0, m;
bool dp[1005][1005];
cin >> n;
for(int i=0;i<n;i++){
cin >> w[i];
sum += w[i];
}
m = sum/2;
for(int i=0; i<n;i++){
for(int j=0;j<=m;j++){
dp[i][j] = false;
}
}
if(sum %2 == 1){
cout << "impossible" << endl;
return 0;
}else{
dp[0][0] = true;
for(int i=0; i<n;i++){
for(int j=0;j<=10000;j++){
if(dp[i][j] == true){
dp[i+1][j+w[i]] =true;
dp[i+1][j] = true;
}
}
}
}
if(dp[n][m] == true){
cout << "possible" << endl;
}else{
cout << "impossible" << endl;
}
return 0;
}
Ronlynes