結果

問題 No.4 おもりと天秤
ユーザー RyuRyu
提出日時 2018-01-10 11:23:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 718 bytes
コンパイル時間 661 ms
コンパイル使用メモリ 66,516 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-25 03:27:40
合計ジャッジ時間 3,505 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 RE -
testcase_06 AC 2 ms
4,376 KB
testcase_07 RE -
testcase_08 AC 2 ms
4,376 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 WA -
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:33:22: 警告: iteration 10001 invokes undefined behavior [-Waggressive-loop-optimizations]
   33 |            if(dp[i][j])
      |               ~~~~~~~^
main.cpp:31:25: 備考: within this loop
   31 |        for(int j = 0; j <= 100000; j++)
      |                       ~~^~~~~~~~~

ソースコード

diff #

#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";
}
0