結果
問題 |
No.458 異なる素数の和
|
ユーザー |
|
提出日時 | 2018-04-15 11:23:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 1,247 bytes |
コンパイル時間 | 1,053 ms |
コンパイル使用メモリ | 97,108 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-26 22:48:32 |
合計ジャッジ時間 | 2,353 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:44:45: warning: iteration 20010 invokes undefined behavior [-Waggressive-loop-optimizations] 44 | for (int i = 0;i <= 20010;i++)dp[i] = -1; | ~~~~~~^~~~ main.cpp:44:26: note: within this loop 44 | for (int i = 0;i <= 20010;i++)dp[i] = -1; | ~~^~~~~~~~ main.cpp:44:45: warning: 'void* __builtin_memset(void*, int, long unsigned int)' writing 80044 bytes into a region of size 80040 overflows the destination [-Wstringop-overflow=] 44 | for (int i = 0;i <= 20010;i++)dp[i] = -1; | ~~~~~~^~~~ main.cpp:41:16: note: destination object 'dp' of size 80040 41 | int m, dp[20010] = { 0 }; | ^~
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <iomanip> #include <vector> #include <map> #include <cmath> #include <queue> #include <utility> #include <functional> #include <deque> #include <cctype> #include <stack> #include <bitset> #include <set> using ll = long long; using namespace std; typedef unsigned long long ull; typedef pair<ll, ll> P; const ll MOD = 1000000007; const ll INF = 1 << 30; const ll INF2 = 9000000000000000000LL; const double INF3 = 900000000000000; const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 }; #define ALL(x) (x).begin(),(x).end() bool bpr[20010]; void sieve(int n) { for (int i = 0;i <= n;i++)bpr[i] = true; bpr[0] = bpr[1] = false; for (int i = 2;i <= n;i++) { if (bpr[i]) for (int j = i * 2;j <= n;j += i)bpr[j] = false; } } int main() { int m, dp[20010] = { 0 }; vector<int>p; cin >> m; for (int i = 0;i <= 20010;i++)dp[i] = -1; dp[0] = 0; sieve(20010); for (int i = 0;i <= m;i++) { if (bpr[i])p.push_back(i); } for (int i = 0;i < p.size();i++) { for (int j = m;j >= 0;j--) { if (p[i] + j <= m&& dp[j] != -1)dp[p[i] + j] = max(dp[p[i] + j], dp[j] + 1); } } cout << dp[m] << endl; }