結果

問題 No.458 異なる素数の和
ユーザー mogurockermogurocker
提出日時 2017-10-14 17:20:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,143 bytes
コンパイル時間 1,418 ms
コンパイル使用メモリ 161,232 KB
実行使用メモリ 180,224 KB
最終ジャッジ日時 2024-04-28 19:34:43
合計ジャッジ時間 4,229 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,632 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 21 ms
20,224 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 211 ms
180,224 KB
testcase_12 WA -
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 WA -
testcase_16 AC 13 ms
27,492 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 67 ms
67,584 KB
testcase_28 AC 210 ms
178,176 KB
testcase_29 WA -
testcase_30 AC 44 ms
54,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n, dp[2300][20005];

bool isPrime(int x) {
	if (x < 2) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

vector<int> getPrimes(int n) {
	vector<int> ret;
	for (int i = 2; i <= n; i++) {
		if (isPrime(i)) ret.push_back(i);
	}
	return ret;
}

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	// FOR(i, 2300) {
	// 	FOR(j, 20005) dp[i][j] = -1;
	// }
	vector<int> p = getPrimes(n);
	for (int i = 0; i < p.size(); i++) {
		dp[i+1][p[i]] = 1;
		FOR(j, n+1) {
			// if (j-p[i] == 0) dp[i+1][j] = 1;
			if (j-p[i] >= 0 && dp[i][j-p[i]] >= 0 && j-p[i] != p[i] && j-p[i] != 1) {
				dp[i+1][j] = max({dp[i+1][j], dp[i][j], dp[i][j-p[i]]+1});
			}
			else dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
		}
	}
	// FOR(i, n+1) cout << dp[p.size()][i] << " ";
	// cout << endl;
	cout << dp[p.size()][n] << endl;
	return 0;
}
0