結果
| 問題 | No.458 異なる素数の和 |
| コンテスト | |
| ユーザー |
tlllune
|
| 提出日時 | 2018-11-10 16:31:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 2,000 ms |
| コード長 | 851 bytes |
| 記録 | |
| コンパイル時間 | 688 ms |
| コンパイル使用メモリ | 78,784 KB |
| 実行使用メモリ | 82,080 KB |
| 最終ジャッジ日時 | 2024-11-24 13:47:48 |
| 合計ジャッジ時間 | 3,028 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:28:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
28 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
ソースコード
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <utility>
#include <set>
#include <map>
using namespace std;
vector<int> sq;
int ssm=0,n;
int dp[1010][20010];
bool f;
int main(){
for(int i=2;ssm<1001;i++){
f=true;
for(int j:sq)f=f and (i%j!=0);
if(f){
ssm+=1;
sq.push_back(i);
}
}
scanf("%d",&n);
for(int i=0;i<20001;i++)dp[0][i]=0;
for(int j=1;j<=1001;j++){
for(int i=20000;i>=0;i--){
dp[j][i]=dp[j-1][i];
if((i==0 or dp[j-1][i]!=0) and sq[j-1]+i<20001)dp[j][i+sq[j-1]]=max(dp[j-1][i]+1,dp[j][i+sq[j-1]]);
}
}
//for(int i=0;i<20;i++)printf("%d ",dp[92][i]);
if(dp[1001][n]==0)dp[1001][n]=-1;
printf("%d\n",dp[1001][n]);
}
tlllune