結果
| 問題 |
No.385 カップ麺生活
|
| コンテスト | |
| ユーザー |
kurenai3110
|
| 提出日時 | 2016-07-01 23:55:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 902 bytes |
| コンパイル時間 | 537 ms |
| コンパイル使用メモリ | 66,776 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-12 01:26:32 |
| 合計ジャッジ時間 | 2,131 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 11 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool dp[10000];
bool so[10000];
void solve(int m, int cnt, vector<int> &c);
int res;
int main()
{
for (int i = 2; i < 10000; i++) {
so[i] = true;
}
for (int i = 2; i < 10000; i++) {
if (so[i]) {
for (int j = i + 1; j < 10000; j++) {
if (so[j]) {
if (!(j%i))so[j] = false;
}
}
}
}
int m, n;
cin >> m >> n;
vector<int> c;
c.resize(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
}
sort(c.begin(), c.end());
solve(m, 1, c);
cout << res+(m/c[0]) << endl;
return 0;
}
void solve(int m, int cnt, vector<int> &c) {
for (int i = 0; i < c.size(); i++) {
int mtmp;
mtmp = m - c[i];
if (mtmp <= 1) break;
if (mtmp > 1) {
if (!dp[mtmp])dp[mtmp] = true;
else continue;
if (so[mtmp]) {
res += cnt;
so[mtmp] = false;
}
solve(mtmp, cnt+1, c);
}
}
}
kurenai3110