結果
| 問題 | No.458 異なる素数の和 |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2026-10-02 23:30:57 |
| 言語 | C++23(gnu拡張gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 2,092 bytes |
| 記録 | |
| コンパイル時間 | 4,335 ms |
| コンパイル使用メモリ | 293,956 KB |
| 実行使用メモリ | 9,920 KB |
| 最終ジャッジ日時 | 2026-10-02 23:31:29 |
| 合計ジャッジ時間 | 25,454 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 TLE * 4 |
ソースコード
#ifdef MAIN
bool __multi__ = 0;
using INT = long long;
namespace XK {
void solve() {
int N; cin >> N;
V<ll> prime;
Rep(i, 2, N + 1) {
bool ok = 1;
for(int j = 2; j * j <= i; j ++) {
if(i % j == 0) {ok = 0; break;}
}
if(ok) prime.pb(i);
}
// rep(i, sz(prime)) cout << prime[i] << " \n"[i == sz(prime) - 1];
map<int, ll> mp;
rep(i, sz(prime)) {
int A = prime[i];
map<int, ll> nmp = mp;
for(auto [x, y] : mp) {
if(x + A <= N) chmax(nmp[x + A], mp[x] + 1);
}
chmax(nmp[A], 1);
swap(nmp, mp);
}
// for(auto [x, y] : mp) cout << "[" << x << ", " << y << "], "; cout << '\n';
cout << (mp[N] == 0 ? -1 : mp[N]);
}
};
#else
#include "cassert"
#include "cmath"
#include "cstdint"
#include "cstdio"
#include "cstdlib"
#include "cstring"
#include "algorithm"
#include "bitset"
#include "chrono"
#include "complex"
#include "deque"
#include "functional"
#include "iostream"
#include "limits"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "sstream"
#include "string"
#include "unordered_map"
#include "unordered_set"
#include "utility"
#include "vector"
#include "array"
using namespace std;
#define int long long
using ll = long long;
using ull = unsigned long long;
const ll INF = 1ll << 60;
const ll LINF = 0x1fffffffffffffff;
const ll MINF = 0x7fffffffffff;
template <class A, class B> bool chmax(A& l, const B& r){ return r > l ? l = r, 1 : 0; }
template <class A, class B> bool chmin(A& l, const B& r){ return r < l ? l = r, 1 : 0; }
#define sz(x) ssize(x)
#define rep(i, a) for(ll i = 0; i < (a); i ++)
#define Rep(i, a, b) for(ll i = (a); i < (b); i ++)
#define rrep(i, a, b) for(ll i = (b); i --> (a); )
#define all(x) begin(x), end(x)
#define fst first
#define snd second
#define pb push_back
template<class T> using V = vector<T>;
template<class T, std::size_t N> using AR = array<T, N>;
#define MAIN
#include __FILE__
signed main() {ios::sync_with_stdio(0);cin.tie(0);fixed(cout).precision(12);int t = 1;if(__multi__) cin >> t;while(t --) XK::solve();}
#endif