結果

問題 No.385 カップ麺生活
ユーザー Iruyan_ZakIruyan_Zak
提出日時 2016-09-18 00:02:59
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,132 bytes
コンパイル時間 1,996 ms
コンパイル使用メモリ 70,152 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 08:35:12
合計ジャッジ時間 3,771 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int ans[10001];
bool is_prime[10001];
int main(){
    int m, n, max_ans=0;
    cin >> m >> n;
    vector<int> c(n);
    for(int i=0; i<n; ++i){
        cin >> c[i];
        if(c[i] < m){
            ans[c[i]] = 1;
            max_ans = 1;
        }
    }
    sort(c.begin(), c.end());
    for(int i=0; i<m; ++i){
        if(ans[i]){
            for(int j=0; j<n; ++j){
                int next_price = i+c[j];
                if(next_price <= m){
                    ans[next_price] = max(ans[next_price], ans[i]+1);
                    max_ans = max(max_ans, ans[next_price]);
                }
            }
        }
    }

    for(int i=0; i<=m; ++i){
        is_prime[i] = 1;
    }
    is_prime[0] = is_prime[1] = 0;

    int prime_n = (int)(sqrt(m)) + 1;
    for(int i=2; i<prime_n; ++i){
        if(is_prime[i]){
            for(int j=2; i*j<=m; ++j){
                is_prime[i*j] = 0;
            }
        }
    }

    for(int i=2; i<m; ++i){
        max_ans += is_prime[m-i] * ans[i];
    }

    cout << max_ans << endl;
}
0