結果

問題 No.458 異なる素数の和
ユーザー megasharesmegashares
提出日時 2018-09-13 14:16:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 941 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 35,500 KB
実行使用メモリ 181,308 KB
最終ジャッジ日時 2023-09-13 19:49:29
合計ジャッジ時間 2,673 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,324 KB
testcase_01 AC 40 ms
100,440 KB
testcase_02 AC 45 ms
115,064 KB
testcase_03 AC 15 ms
50,840 KB
testcase_04 AC 17 ms
56,996 KB
testcase_05 AC 82 ms
164,160 KB
testcase_06 AC 43 ms
110,864 KB
testcase_07 AC 3 ms
11,452 KB
testcase_08 AC 80 ms
165,000 KB
testcase_09 AC 8 ms
30,068 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 11 ms
38,360 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 42 ms
108,728 KB
testcase_28 AC 91 ms
178,080 KB
testcase_29 AC 6 ms
21,800 KB
testcase_30 AC 30 ms
86,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <math.h>
#include <limits.h>

int snt(int a, int arr[], int max) {
	int i;

	for (i = 1; i <= max; i++) {
		if (a == arr[i]) {
			return 1;
		}
	}

	return 0;
}

int findMax(int a, int b) {
	return a > b ? a : b;
}

int f[10000][20000] = {};
const int inf = -INT_MAX;

int main() {
	int n;
	int i, j;
	int max;
	int check[21000] = {};
	int arr[10000] = {};


	scanf("%d", &n);

	for (i = 2; i <= sqrt(n); i++) {
		for (j = 2; j <= n / i; j++) {
			check[i*j] = 1;
		}
	}

	max = 1;
	for (i = 2; i <= n; i++) {
		if (!check[i]) arr[max++] = i;
	}
	max--;

	for (i = 1; i <= n; i++) {
		f[0][i] = inf;
	}

	for (i = 1; i <= max; i++) {
		for (j = 0; j <= n; j++) {
			if (j - arr[i] >= 0) {
				f[i][j] = findMax(f[i - 1][j], f[i - 1][j - arr[i]] + 1);
			}
			else {
				f[i][j] = f[i - 1][j];
			}
		}
	}


	int result = (f[max][n] <0 ? -1 : f[max][n]);
	printf("%d", result);
	getchar(); getchar();

	return 0;
}
0