結果
| 問題 |
No.385 カップ麺生活
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2017-11-23 20:26:00 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 760 bytes |
| コンパイル時間 | 908 ms |
| コンパイル使用メモリ | 101,216 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-12 22:35:09 |
| 合計ジャッジ時間 | 1,668 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int m; rd(m);
int n; rd(n);
auto a=readln.split.to!(int[]);
auto rec=new long[](m+1);
fill(rec, -1); rec[0]=0;
foreach(e; a)for(int i=0; i+e<=m ;i++){
if(rec[i]>=0) chmax(rec[i+e], rec[i]+1);
}
long sum=0;
foreach(long i, e; rec)if(e>0){
if(isPrime(m-i)) sum+=e;
}
writeln(sum+(m/reduce!(min)(a)));
}
bool isPrime(long x){
if(x<=1) return false;
bool ok=true;
for(long i=2; i*i<=x; i++){
ok&=(x%i>0);
}
return ok;
}
void chmax(T)(ref T x, T y){
if(x<y) x=y;
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
ikd