結果

問題 No.385 カップ麺生活
ユーザー rullonzrullonz
提出日時 2017-10-28 20:40:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,060 bytes
コンパイル時間 1,946 ms
コンパイル使用メモリ 165,888 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:38:32
合計ジャッジ時間 2,683 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct edge {int /*from**/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
//static const int INF = 2147483647;
//static const long long INf = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define itn int
#define scnaf scanf
#define reutnr return
#define scamf scanf
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define int ll

VL primes;
bool is_prime[11451];
int m,n;
int noodles[25];
int dp[11451];

void sieve(int n){   //n以下の素数の数を返す
    for(int i=0;i<=n;i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            primes.pb(i);
            for(int j=2*i;j<=n;j += i) is_prime[j] = false;
        }
    }
    return;
}

void print(){
    for(int i=0;i<=m;i++){
       printf("%lld ",dp[i]);
    }
    return;
}

signed main(){
    scanf("%lld%lld",&m,&n);
    sieve(m);
    int tmpmin=INF;
    for(int i=0;i<n;i++){
        scanf("%lld",&noodles[i]);
        if(noodles[i]<tmpmin) tmpmin = noodles[i];
    }

    memset(dp,-1,sizeof(dp));
    dp[m] = 0;
    for(int i=0;i<n;i++){
        for(int j=m;j>=0;j--){
            if(j-noodles[i]>=0&&dp[j]!=-1){
                dp[j-noodles[i]] = max(dp[j]+1,dp[j-noodles[i]]);
            }
        }
    }
    //print();
    int ans = m / tmpmin;
    for(int i=0;i<primes.size();i++){
        int k = primes[i];
        if(dp[k]!=-1) ans += dp[k];
    }
    printf("%lld\n",ans);
    return 0;
}
0