結果

問題 No.385 カップ麺生活
ユーザー rapurasurapurasu
提出日時 2016-08-08 14:26:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 1,234 ms
コンパイル使用メモリ 160,212 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:35:46
合計ジャッジ時間 2,287 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 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 1 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 1 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:38:18: warning: iteration 9999 invokes undefined behavior [-Waggressive-loop-optimizations]
   38 |         if(used[i]==true){
      |            ~~~~~~^
main.cpp:37:18: note: within this loop
   37 |     for(int i=2;i<=10001;i++){
      |                 ~^~~~~~~

ソースコード

diff #

 #include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)

int M,N;
int dp[10001];
int C[21];
int used[10001];
int main(){
    cin>>M>>N;
    REP(i,10001){
        dp[i]=0;
    }
    REP(i,N){
       cin>>C[i];
    }
    dp[M]=0;
    for(int i=M;i>=0;i--){
        if(i!=M&&dp[i]==0)continue;
        REP(j,N){
            if(i-C[j]>=0){
               dp[i-C[j]]=max(dp[i-C[j]],dp[i]+1);
            }
        }
    }
    long long ans=0;
    int ma=0;
    REP(i,M){
        ma=max(dp[i],ma);
    }
    ans+=ma;
    //素数
    REP(i,10001){
       used[i]=true;
    }
    for(int i=2;i<=10001;i++){
        if(used[i]==true){
           ans+=dp[i];
           for(int j=2*i;j<=10001;j+=i){
               used[j]=false;
           }
        }
    }
    cout<<ans<<endl;
}
0