結果

問題 No.458 異なる素数の和
ユーザー BantakoBantako
提出日時 2017-07-27 11:20:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 797 bytes
コンパイル時間 1,780 ms
コンパイル使用メモリ 157,800 KB
実行使用メモリ 180,580 KB
最終ジャッジ日時 2024-04-18 08:49:08
合計ジャッジ時間 7,790 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
180,476 KB
testcase_01 AC 157 ms
180,352 KB
testcase_02 AC 153 ms
180,224 KB
testcase_03 AC 154 ms
180,480 KB
testcase_04 AC 148 ms
180,480 KB
testcase_05 AC 152 ms
180,460 KB
testcase_06 AC 154 ms
180,480 KB
testcase_07 AC 153 ms
180,352 KB
testcase_08 AC 160 ms
180,276 KB
testcase_09 AC 156 ms
180,480 KB
testcase_10 AC 153 ms
180,244 KB
testcase_11 AC 157 ms
180,352 KB
testcase_12 AC 163 ms
180,432 KB
testcase_13 AC 162 ms
180,388 KB
testcase_14 AC 170 ms
180,292 KB
testcase_15 AC 189 ms
180,460 KB
testcase_16 AC 174 ms
180,260 KB
testcase_17 AC 158 ms
180,480 KB
testcase_18 AC 169 ms
180,540 KB
testcase_19 AC 161 ms
180,580 KB
testcase_20 AC 166 ms
180,352 KB
testcase_21 AC 218 ms
180,412 KB
testcase_22 AC 152 ms
180,380 KB
testcase_23 AC 157 ms
180,352 KB
testcase_24 AC 168 ms
180,480 KB
testcase_25 AC 179 ms
180,240 KB
testcase_26 AC 173 ms
180,480 KB
testcase_27 AC 147 ms
180,396 KB
testcase_28 AC 150 ms
180,480 KB
testcase_29 AC 151 ms
180,576 KB
testcase_30 AC 146 ms
180,260 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:5:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
    5 | main(){
      | ^~~~
main.cpp: In function ‘int main()’:
main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
int prime[20001];
int p[2262];
int dp[2263][20001];
main(){
    for(int i = 2;i*i <= 20000;i++){
        if(prime[i])continue;
        for(int j = i*2;j <= 20000;j+=i){
            prime[j] = 1;
        }
    }
    int count = 0;
    for(int i = 2;i <= 20000;i++){
        if(prime[i])continue;
        p[count] = i;
        count++;
    }
    for(int i = 0;i < 2262;i++){
        for(int j = 0;j <= 20000;j++){
            dp[i+1][j] = dp[i][j];
            if(j < p[i])continue;
            if(j-p[i]==0){
                dp[i+1][j] = std::max(dp[i][j],1);
            }else if(dp[i][j-p[i]]!=0){
                dp[i+1][j] = std::max(dp[i][j],dp[i][j-p[i]]+1);
            }
        }
    }
    int N;
    scanf("%d",&N);
    printf("%d\n",dp[2262][N]?dp[2262][N]:-1);
}
0