結果

問題 No.385 カップ麺生活
ユーザー kurenai3110kurenai3110
提出日時 2016-07-01 23:55:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 902 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 66,492 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 06:20:17
合計ジャッジ時間 2,169 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
6,816 KB
testcase_01 AC 18 ms
6,944 KB
testcase_02 AC 17 ms
6,944 KB
testcase_03 AC 17 ms
6,944 KB
testcase_04 AC 17 ms
6,940 KB
testcase_05 AC 17 ms
6,940 KB
testcase_06 AC 17 ms
6,944 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 17 ms
6,944 KB
testcase_10 AC 18 ms
6,940 KB
testcase_11 AC 17 ms
6,940 KB
testcase_12 AC 17 ms
6,944 KB
testcase_13 WA -
testcase_14 AC 16 ms
6,940 KB
testcase_15 WA -
testcase_16 AC 17 ms
6,944 KB
testcase_17 AC 17 ms
6,944 KB
testcase_18 WA -
testcase_19 AC 16 ms
6,940 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 18 ms
6,944 KB
testcase_23 WA -
testcase_24 AC 18 ms
6,940 KB
testcase_25 AC 17 ms
6,944 KB
testcase_26 AC 18 ms
6,944 KB
testcase_27 AC 16 ms
6,944 KB
testcase_28 WA -
testcase_29 AC 17 ms
6,940 KB
testcase_30 WA -
testcase_31 AC 19 ms
6,944 KB
testcase_32 AC 19 ms
6,944 KB
testcase_33 WA -
testcase_34 AC 17 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
		}
	}
}

0