結果
| 問題 |
No.458 異なる素数の和
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-08-31 14:32:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 45 ms / 2,000 ms |
| コード長 | 2,384 bytes |
| コンパイル時間 | 1,066 ms |
| コンパイル使用メモリ | 112,468 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-13 22:32:35 |
| 合計ジャッジ時間 | 2,558 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:103:15: warning: iteration 20010 invokes undefined behavior [-Waggressive-loop-optimizations]
103 | dp[i] = -1;
| ~~~~~~^~~~
main.cpp:42:37: note: within this loop
42 | #define REP(i, n) for (int i = 0; i < (n); i++)
| ^
main.cpp:101:5: note: in expansion of macro 'REP'
101 | REP(i, MAX + 1)
| ^~~
main.cpp:103:15: warning: 'void* __builtin_memset(void*, int, long unsigned int)' writing 80044 bytes into a region of size 80040 overflows the destination [-Wstringop-overflow=]
103 | dp[i] = -1;
| ~~~~~~^~~~
main.cpp:90:5: note: destination object 'dp' of size 80040
90 | int dp[MAX];
| ^~
ソースコード
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
/*
PascalCase クラス名
camelCase メソッド名,関数名,変数名
snake_case ファイル名,名前空間,std のメソッド名,変数名,型名に準じる場合
SNAKE_CASE マクロ名,static const 定数,列挙体
*/
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define Cout(obj) cout << obj << endl
#define Size(obj) (int)(obj).size()
#define fcout cout << fixed << setprecision(10)
#define fi first
#define se second
using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
int to, cost;
};
const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int MAX = 1e4 * 2 + 10;
bool isPrime[MAX];
void prime()
{
memset(isPrime, true, sizeof(isPrime));
isPrime[0] = isPrime[1] = false;
FOR(i, 2, sqrt(MAX) + 1)
{
if(isPrime[i])
{
for(int j = i * 2; j < MAX + 1; j += i)
{
isPrime[j] = false;
}
}
}
}
int dp[MAX];
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
prime();
REP(i, MAX + 1)
{
dp[i] = -1;
}
dp[0] = 0;
FOR(i, 1, MAX)
{
if(isPrime[i])
{
for(int j = N; j >= 0; j--)
{
if(dp[j] == -1 || MAX < i + j) continue;
dp[i + j] = max(dp[i + j], dp[j] + 1);
}
}
}
Cout(dp[N]);
return 0;
}