QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#965 | #639142 | #9457. Prime Set | ship2077 | supepapupu | Success! | 2024-10-13 18:24:38 | 2024-10-13 18:24:40 |
Details
Extra Test:
Wrong Answer
time: 11ms
memory: 14100kb
input:
1000 1 0 4 7 6 5 9 6 5 7 9 8 9 2 7 5 10 5 7 10 3 5 2 8 7 4 4 4 9 3 9 2 6 4 0 5 1 1 3 4 3 8 8 7 3 10 4 1 7 5 8 2 10 1 1 9 1 4 3 9 6 8 6 10 4 6 7 3 10 9 6 8 2 2 6 9 1 1 1 8 10 5 7 1 4 4 10 5 2 8 3 10 4 1 8 2 6 1 8 0 8 7 10 2 6 5 3 8 4 2 10 5 6 3 6 3 4 9 4 1 10 1 5 3 9 1 6 10 7 10 6 9 9 2 2 10 8 5 8 6 ...
output:
0 7 4 7 0 3 8 2 7 2 8 0 4 6 5 9 0 2 2 2 4 4 2 0 0 6 0 0 0 9 0 6 10 8 0 0 0 6 7 2 2 2 10 2 0 3 0 0 0 6 0 2 2 8 5 2 8 4 2 5 3 0 0 9 2 0 0 4 5 6 7 10 0 7 9 9 6 3 10 6 6 5 0 0 9 4 4 0 2 2 0 9 7 0 1 2 0 0 0 8 0 6 0 7 6 0 10 2 5 0 0 2 2 4 2 4 2 2 9 6 4 6 5 9 2 3 4 0 6 3 2 0 0 6 3 10 6 2 2 0 0 9 0 0 0 2 0 ...
result:
wrong answer 70th lines differ - expected: '5', found: '6'
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639142 | #9457. Prime Set | supepapupu | WA | 346ms | 20868kb | C++20 | 3.6kb | 2024-10-13 18:04:48 | 2024-10-13 18:39:31 |
answer
#include <bits/stdc++.h>
#define x first
#define y second
#define el '\n'
#define debug(x) cout << #x << ": " << x << el
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 3010, M = 1e7 + 10, INF = 0x3f3f3f3f, mod = 998244353;
namespace MF {
const int INF = 1e8;
int S, T = N - 1;
int h[N], e[M], f[M], ne[M], idx;
int q[N], d[N], cur[N];
void clear() {
memset(h, -1, sizeof h), idx = 0;
}
void add_edge(int a, int b, int c) {
// cout << a << ' ' << b << ' ' << c << el;
e[idx] = b, f[idx] = c, ne[idx] = h[a], h[a] = idx++;
e[idx] = a, f[idx] = 0, ne[idx] = h[b], h[b] = idx++;
}
bool bfs() {
int hh = 0, tt = 0;
memset(d, -1, sizeof d);
q[0] = S, d[S] = 0, cur[S] = h[S];
while (hh <= tt) {
int t = q[hh++];
for (int i = h[t]; ~i; i = ne[i]) {
int ver = e[i];
if (d[ver] == -1 && f[i]) {
d[ver] = d[t] + 1;
cur[ver] = h[ver];
if (ver == T) return 1;
q[++tt] = ver;
}
}
}
return 0;
}
int find(int u, int limit) {
if (u == T) return limit;
int flow = 0;
for (int i = cur[u]; ~i && flow < limit; i = ne[i]) {
cur[u] = i;
int ver = e[i];
if (d[ver] == d[u] + 1 && f[i]) {
int t = find(ver, min(f[i], limit - flow));
if (!t) d[ver] = -1;
f[i] -= t, f[i ^ 1] += t, flow += t;
}
}
return flow;
}
int dinic() {
int r = 0, flow;
while (bfs()) while (flow = find(S, INF)) r += flow;
return r;
}
}
int primes[2000010], idx;
bool st[2000010];
// 线性筛质数
void sieve(int n) {
for (int i = 2; i <= n; ++i) {
if (!st[i]) primes[idx++] = i;
for (int j = 0; primes[j] <= n / i; ++j) {
st[i * primes[j]] = 1;
if (i % primes[j] == 0) break;
}
}
}
void solve() {
MF::clear();
int n, k; cin >> n >> k;
int one = 0;
vector<int> a(n + 1);
MF::add_edge(MF::S, N - 2, 0);
map<int, int> odd, even;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (a[i] == 1) ++one;
else {
if (a[i] & 1) ++odd[a[i]];
else ++even[a[i]];
}
}
int valid = 0;
for (int i = 1; i <= n; ++i) {
int t = 0;
for (int j = 1; j <= n; ++j)
if (!st[a[i] + a[j]]) {
t = 1; break;
}
valid += t;
}
int tot = 0;
map<int, int> mp;
for (auto[a, b]: odd) {
mp[a] = ++tot;
MF::add_edge(MF::S, tot, b);
}
for (auto[a, b]: even) {
mp[a] = ++tot;
MF::add_edge(tot, MF::T, b);
if (!st[1 + a]) MF::add_edge(N - 2, tot, INF);
}
for (auto[a, b]: odd) for (auto[c, d]: even) {
if (!st[a + c]) MF::add_edge(mp[a], mp[c], b + d);
}
int two = MF::dinic();
for (int i = 1; i <= one; ++i) {
++MF::f[0];
int t = MF::dinic();
if (t) ++two;
else {
two += (one - i + 1) / 2;
break;
}
}
two = min(two, k);
cout << min(two * 2 + (k - two), valid) << el;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
sieve(2e6);
int tcase = 1;
cin >> tcase;
while (tcase--) solve();
}