結果

問題 No.247 線形計画問題もどき
ユーザー imulanimulan
提出日時 2016-12-10 05:43:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,003 bytes
コンパイル時間 1,531 ms
コンパイル使用メモリ 165,820 KB
実行使用メモリ 43,484 KB
最終ジャッジ日時 2023-09-21 18:21:30
合計ジャッジ時間 3,302 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
43,316 KB
testcase_01 AC 16 ms
43,048 KB
testcase_02 AC 53 ms
43,364 KB
testcase_03 AC 16 ms
42,912 KB
testcase_04 AC 16 ms
42,988 KB
testcase_05 AC 16 ms
43,072 KB
testcase_06 AC 16 ms
43,084 KB
testcase_07 AC 17 ms
43,368 KB
testcase_08 AC 16 ms
43,224 KB
testcase_09 AC 16 ms
43,052 KB
testcase_10 AC 16 ms
43,372 KB
testcase_11 AC 16 ms
42,988 KB
testcase_12 AC 16 ms
42,912 KB
testcase_13 AC 16 ms
43,004 KB
testcase_14 AC 15 ms
42,912 KB
testcase_15 AC 15 ms
42,916 KB
testcase_16 AC 16 ms
42,984 KB
testcase_17 AC 21 ms
43,392 KB
testcase_18 AC 16 ms
43,076 KB
testcase_19 AC 29 ms
43,368 KB
testcase_20 AC 34 ms
43,328 KB
testcase_21 AC 22 ms
43,364 KB
testcase_22 AC 23 ms
43,400 KB
testcase_23 AC 21 ms
43,300 KB
testcase_24 AC 35 ms
43,484 KB
testcase_25 AC 29 ms
43,392 KB
testcase_26 AC 18 ms
43,360 KB
testcase_27 AC 20 ms
43,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int INF=123456789;
int dp[101][100001];
int min_cost[100001];

int main()
{
    int C,N;
    scanf(" %d %d", &C, &N);
    vector<int> a(N);
    rep(i,N) scanf(" %d", &a[i]);

    fill(dp[0],dp[101],INF);
    dp[0][0]=0;
    for(int i=1; i<=N; ++i)
    {
        rep(j,a[i-1])
        {
            dp[i][j]=min(dp[i][j],dp[i-1][j]);
            min_cost[j]=dp[i-1][j];
        }

        for(int j=a[i-1]; j<=C; ++j)
        {
            int idx=j%a[i-1];
            ++min_cost[idx];
            min_cost[idx] = min(min_cost[idx], dp[i-1][j]);
            dp[i][j] = min(dp[i][j],min_cost[idx]);
        }
    }

    int ans=dp[N][C];
    if(ans==INF) ans=-1;
    printf("%d\n", ans);
    return 0;
}
0