QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#636674 | #9457. Prime Set | ucup-team191# | AC ✓ | 27ms | 12616kb | C++23 | 2.7kb | 2024-10-13 01:47:35 | 2024-10-13 19:28:29 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <vector>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef vector < int > vi;
const int N = 3e3 + 50;
const int M = 2e6 + 500;
int comp[M], na, nb, uzeoA[N], uzeoB[N];
vector < vi > g;
vector < int > btoa;
int AA[N], BB[N];
bool dfs(int a, int L) {
if (AA[a] != L) return 0;
AA[a] = -1;
for (int b : g[a]) if (BB[b] == L + 1) {
BB[b] = 0;
if (btoa[b] == -1 || dfs(btoa[b], L + 1)) {
return btoa[b] = a, 1;
}
}
return 0;
}
int hopcroftKarp() {
int res = 0;
int na = (int)g.size();
vi cur, next;
for (;;) {
fill(AA, AA + na, 0);
fill(BB, BB + nb, 0);
cur.clear();
for(int a : btoa) if(a != -1) AA[a] = -1;
for(int a = 0;a < na;a++) if(AA[a] == 0) cur.PB(a);
for (int lay = 1;;lay++) {
bool islast = 0;
next.clear();
for (int a : cur) for (int b : g[a]) {
if(btoa[b] == -1) {
BB[b] = lay;
islast = 1;
} else if(btoa[b] != a && !BB[b]) {
BB[b] = lay;
next.push_back(btoa[b]);
}
}
if(islast) break;
if (next.empty()) return res;
for (int a : next) AA[a] = lay;
cur.swap(next);
}
for(int a = 0;a < na;a++)
res += dfs(a, 0);
}
}
int A[N], B[N];
void precompute() {
comp[1] = 1;
for(int i = 2;i < M;i++) {
if(comp[i]) continue;
for(int j = 2 * i;j < M;j += i)
comp[j] = 1;
}
}
void solve() {
int n, k; scanf("%d%d", &n, &k);
na = 0, nb = 0;
int jen = 0;
for(int i = 0;i < n;i++) {
int x; scanf("%d", &x);
jen += (x == 1);
if(x & 1) uzeoA[na] = 0, A[na++] = x;
else uzeoB[nb] = 0, B[nb++] = x;
}
g.clear();
btoa.clear();
btoa.resize(nb);
fill(btoa.begin(), btoa.end(), -1);
sort(A, A + na); reverse(A, A + na);
for(int i = 0;i < na;i++) {
if(A[i] == 1) break;
vi tmp;
for(int j = 0;j < nb;j++) {
if(!comp[A[i] + B[j]]) uzeoA[i] = 1, uzeoB[j] = 1, tmp.PB(j);
}
g.PB(tmp);
}
int old_ans = hopcroftKarp();
int start = 0;
while(start < na && A[start] != 1) start++;
if(na - start > 1) {
for(int i = 0;i < na;i++) if(A[i] == 1) uzeoA[i] = 1;
}
for(int i = start;i < na;i++) {
vi tmp;
for(int j = 0;j < nb;j++) {
if(!comp[A[i] + B[j]]) uzeoA[i] = 1, uzeoB[j] = 1, tmp.PB(j);
}
g.PB(tmp);
}
int max_ans = 0;
for(int i = 0;i < na;i++) max_ans += uzeoA[i];
for(int i = 0;i < nb;i++) max_ans += uzeoB[i];
for(int &y : btoa) y = -1;
int new_ans = hopcroftKarp();
int mm = new_ans + (jen - (new_ans - old_ans)) / 2;
if(k <= mm) printf("%d\n", 2 * k);
else printf("%d\n", min(max_ans, k + mm));
}
int main() {
precompute();
int T; scanf("%d", &T);
for(;T--;) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 10ms
memory: 11612kb
input:
4 4 2 2 3 4 5 5 3 3 4 12 3 6 6 3 1 3 6 8 1 1 1 0 1
output:
4 3 6 0
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 27ms
memory: 12616kb
input:
110 3 3 2 2 2 3 1 1 1 1 3 2 1 1 1 3 3 1 1 1 4 2 1 1 1 1 10 7 1 1 1 2 4 6 8 10 12 14 18 1 10 5 9 4 10 7 2 4 9 1 6 1 4 9 2 4 9 7 19 5 1 6 1 8 8 1 5 10 9 2 10 2 1 9 6 10 4 3 6 14 4 6 6 8 9 5 3 4 9 2 2 1 10 10 1 15 10 5 4 2 4 10 1 8 4 10 3 10 3 7 10 4 17 5 10 7 2 4 3 1 10 8 2 8 3 4 1 1 1 1 1 20 6 8 4 6 ...
output:
0 2 3 3 4 8 2 10 8 15 10 12 10 10 12 16 10 10 12 16 14 13 13 14 17 0 19 12 12 11 16 10 19 2 12 10 5 14 10 10 13 2 18 2 4 4 11 8 11 8 0 10 10 0 10 0 8 15 12 11 13 18 10 17 9 8 20 19 13 6 4 6 11 9 13 11 6 2 8 12 17 14 6 2 20 2 18 17 6 2 10 0 7 16 2 2 0 2 18 14 11 8 4 6 0 19 890 204 2746 2372
result:
ok 110 lines
Extra Test:
score: 0
Extra Test Passed