結果

問題 No.247 線形計画問題もどき
ユーザー syoken_desukasyoken_desuka
提出日時 2015-07-18 00:38:32
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,426 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 92,572 KB
実行使用メモリ 7,444 KB
最終ジャッジ日時 2023-09-22 18:41:23
合計ジャッジ時間 6,626 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:51:22: warning: iteration 10001 invokes undefined behavior [-Waggressive-loop-optimizations]
             dp[i][j] = 10000000;
             ~~~~~~~~~^~~~~~~~~~
main.cpp:27:36: note: within this loop
 #define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
                                    ^
main.cpp:28:18: note: in expansion of macro ‘REP’
 #define rep(i,n) REP(i,0,n)
                  ^~~
main.cpp:49:9: note: in expansion of macro ‘rep’
         rep(j,100001)
         ^~~

ソースコード

diff #

#include <algorithm>
#include <array>
#include <sstream>
#include <cstdio>
#include <functional>
#include <cstdlib>
#include <cctype>
#include <ostream>
#include<complex>
#include <cmath>
#include <iostream>
#include <stack>
#include <fstream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <string>
using namespace std;
#define OB (bitset<32>)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define ALLOF(c) begin(), (c),end()

typedef long long ll;

#define PI acos(-1)
#define EPS 0.000000001
#define MOD 1000000007



int main()
{  
    int dp[101][10001];
    int c;
    int n;
    int a[100];
    cin >>c >> n;
    fill(a,a+100,-1);//invalid error on sort
    rep(i,101)
    {
        rep(j,100001)
        {
            dp[i][j] = 10000000;
        }
    }
    rep(i,n)
    {
        cin >> a[i];
    }
    sort(a,a+100,greater<int>());
    dp[0][0] = 0;
    rep(i,n+1)
    {
        rep(j,c+1)
        {
            if (j < a[i])
            {
                dp[i+1][j]= dp[i][j];
            }
            else
            {
                dp[i+1][j] = min(dp[i][j],dp[i+1][j-a[i]]+1);
            }
        }
    }
    if (dp[n][c]!= MOD)
    {
        cout << dp[n][c] << endl;
        return 0;
    }
    cout << "-1" << endl;
    return 0;
}

0