結果

問題 No.247 線形計画問題もどき
ユーザー syoken_desukasyoken_desuka
提出日時 2015-07-18 00:02:02
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,894 bytes
コンパイル時間 2,577 ms
コンパイル使用メモリ 99,892 KB
実行使用メモリ 17,416 KB
最終ジャッジ日時 2023-09-22 18:34:42
合計ジャッジ時間 4,313 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
9,284 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

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 c;
    int n;
    int a[100];
    cin >>c >> n;
    fill(a,a+100,-1);//invalid error on sort
    rep(i,n)
    {
        cin >> a[i];
    }
    map<int,int> dp[10001];
    dp[0].insert(make_pair(0,0));
    sort(a,a+100,greater<int>());
    rep(i,n)
    {
        for (auto ittr = dp[i].begin();  ittr != dp[i].end() ; ittr++)
        {
            for (int k = 0;; k++)
            {
                int x = ittr->first;
                int y = ittr->second;
                if ((x + k*a[i]) > c)
                {
                    break;
                }
                auto next = dp[i+1].find(x + k*a[i]);
                if (next == dp[i+1].end())
                {
                    dp[i+1].insert(make_pair(x +k*a[i],y+k));
                    continue;
                }
                if ( next->second > y+k)
                {
                    dp[i+1].erase(next->first);
                    dp[i+1].insert(make_pair(x+k*a[i],y+k));
                }
            }
        } 
    }
    if (dp[n].find(c) != dp[n].end())
    {
        int ans = dp[n].find(c)->second;
        cout << ans <<endl;
        return 0;
    }
    cout << "-1" << endl;
    return 0;
}

0