QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#634972#9457. Prime Setucup-team3670#AC ✓61ms5244kbC++171.6kb2024-10-12 18:31:412024-10-13 18:38:57

Judging History

你现在查看的是测评时间为 2024-10-13 18:38:57 的历史记录

  • [2024-10-13 19:27:58]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:62ms
  • 内存:5160kb
  • [2024-10-13 19:27:24]
  • hack成功,自动添加数据
  • (/hack/967)
  • [2024-10-13 18:38:57]
  • 管理员手动重测本题所有得分≥97分的提交记录
  • 测评结果:100
  • 用时:61ms
  • 内存:5244kb
  • [2024-10-13 18:24:51]
  • hack成功,自动添加数据
  • (/hack/965)
  • [2024-10-13 18:17:54]
  • hack成功,自动添加数据
  • (/hack/963)
  • [2024-10-12 18:31:41]
  • 评测
  • 测评结果:100
  • 用时:63ms
  • 内存:5204kb
  • [2024-10-12 18:31:41]
  • 提交

answer

#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)

using namespace std;

int n, k;
vector<int> a;

bool read(){
	if (!(cin >> n >> k))
		return false;
	a.resize(n);
	forn(i, n) cin >> a[i];
	return true;
}

const int N = int(2e6) + 13;

vector<char> isp;

void sieve(){
	isp.resize(N, true);
	fore(i, 2, N){
		if (!isp[i]) continue;
		for (long long j = i * 1ll * i; j < N; j += i)
			isp[j] = false;
	}
	isp[0] = isp[1] = false;
}

vector<int> mt, used;
int T;

bool try_kuhn(int v){
	if (used[v] == T) return false;
	used[v] = T;
	forn(u, n) if (a[u] % 2 == 0 && isp[a[v] + a[u]] && mt[u] == -1){
		mt[u] = v;
		return true;
	}
	forn(u, n) if (a[u] % 2 == 0 && isp[a[v] + a[u]] && mt[u] != -1 && try_kuhn(mt[u])){
		mt[u] = v;
		return true;
	}
	return false;
}

void solve(){
	sort(a.rbegin(), a.rend());
	used.assign(n, 0);
	mt.assign(n, -1);
	int mtsiz = 0;
	int ones = 0;
	T = 1;
	forn(i, n) if (a[i] % 2 == 1){
		if (try_kuhn(i)){
			++T;
			++mtsiz;
		}
		else if (a[i] == 1){
			++ones;
		}
	}
	int tot = 0;
	forn(i, n){
		bool ok = false;
		forn(j, n) if (i != j && isp[a[i] + a[j]])
			ok = true;
		tot += ok;
	}
	mtsiz += ones / 2;
	if (mtsiz >= k){
		cout << k * 2 << '\n';
		return;
	}
	if (mtsiz + (tot - mtsiz * 2) >= k){
		cout << 2 * mtsiz + (k - mtsiz) << '\n';
		return;
	}
	cout << tot << '\n';
}

int main(){
	sieve();
	cin.tie(0);
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--){
		read();
		solve();
	}
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 5140kb

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: 61ms
memory: 5244kb

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