結果

問題 No.732 3PrimeCounting
ユーザー ldsybldsyb
提出日時 2018-09-07 23:04:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,105 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 176,976 KB
実行使用メモリ 10,656 KB
最終ジャッジ日時 2024-05-07 05:25:09
合計ジャッジ時間 67,235 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
10,656 KB
testcase_01 AC 133 ms
5,376 KB
testcase_02 AC 139 ms
5,376 KB
testcase_03 AC 135 ms
5,376 KB
testcase_04 AC 138 ms
5,376 KB
testcase_05 AC 138 ms
5,376 KB
testcase_06 AC 140 ms
5,376 KB
testcase_07 AC 142 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 TLE -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 TLE -
testcase_49 TLE -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 TLE -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int64_t solve(int64_t n)
{
	auto is_prime = [](int64_t x) {
		if (x < 2)
		{
			return false;
		}
		if (x == 2)
		{
			return true;
		}
		for (int64_t i = 2; i * i <= x; i++)
		{
			if (x % i == 0)
			{
				return false;
			}
		}
		return true;
	};
	vector<int64_t> ps;
	ps.emplace_back(2);
	for (int64_t i = 3; i <= n; i += 2)
	{
		if (is_prime(i))
		{
			ps.emplace_back(i);
		}
	}
	int64_t ans = 0, m = ps.size();
	vector<vector<vector<bool>>> puni(2, vector<vector<bool>>(4, vector<bool>(300000, false)));
	puni[0][0][0] = true;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 300000; k++)
			{
				puni[(i + 1) % 2][j][k] = puni[(i + 1) % 2][j][k] || puni[i % 2][j][k];
				if (k + ps[i] < 300000)
				{
					puni[(i + 1) % 2][j + 1][k + ps[i]] = puni[(i + 1) % 2][j + 1][k + ps[i]] || puni[i % 2][j][k];
				}
			}
		}
	}
	for (int k = 0; k < 300000; k++)
	{
		if (is_prime(k) && puni[m % 2][3][k])
		{
			ans++;
		}
	}
	return ans;
}

int main()
{
	int64_t n;
	cin >> n;
	cout << solve(n) << endl;
	return 0;
}
0