QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#897541#3267. 分手是祝愿Grand_Elf100 ✓36ms14260kbC++171.3kb2025-02-13 21:23:572025-02-13 21:24:00

Judging History

This is the latest submission verdict.

  • [2025-02-13 21:24:00]
  • Judged
  • Verdict: 100
  • Time: 36ms
  • Memory: 14260kb
  • [2025-02-13 21:23:57]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
const int mod = 1e5 + 3;

int n, k, cnt, a[N], g[N];
vector<int> fac[N];

int qpow(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = 1ll * res * x % mod;
		}
		x = 1ll * x * x % mod;
		y >>= 1;
	}
	return res;
}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j += i) {
			fac[j].emplace_back(i);
		}
	}
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = n; i >= 1; i--) {
		if (a[i]) {
			cnt++;
			for (int j : fac[i]) {
				a[j] ^= 1;
			}
		}
	}
	if (cnt <= k) {
		int ans = cnt;
		for (int i = 1; i <= n; i++) {
			ans = 1ll * ans * i % mod;
		}
		cout << ans << '\n';
		return 0;
	}
	int invn = qpow(n, mod - 2);
	g[n] = 0, g[n - 1] = mod - 1;
	for (int i = n - 2; i >= k; i--) {
		int coe = 1ll * n * qpow(i + 1, mod - 2) % mod;
		g[i] = g[i + 1] - 1ll * (n - (i + 1)) * invn % mod * g[i + 2] % mod;
		if (g[i] < 0) {
			g[i] += mod;
		}
		g[i]--;
		if (g[i] < 0) {
			g[i] += mod;
		}
		g[i] = 1ll * coe * g[i] % mod;
	}
	int x = k - g[k];
	if (x < 0) {
		x += mod;
	}
	int ans = x + g[cnt];
	if (ans >= mod) {
		ans -= mod;
	}
	for (int i = 1; i <= n; i++) {
		ans = 1ll * ans * i % mod;
	}
	cout << ans << '\n';

	return 0;
}

詳細信息


Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 0ms
memory: 5952kb

input:

4 4
0 1 1 0

output:

48

result:

ok single line: '48'

Test #2:

score: 5
Accepted
time: 0ms
memory: 6016kb

input:

4 3
1 1 1 0

output:

72

result:

ok single line: '72'

Test #3:

score: 5
Accepted
time: 0ms
memory: 6016kb

input:

6 6
1 1 1 1 1 1

output:

3600

result:

ok single line: '3600'

Test #4:

score: 5
Accepted
time: 0ms
memory: 6016kb

input:

7 1
0 0 1 1 0 1 1

output:

55229

result:

ok single line: '55229'

Test #5:

score: 5
Accepted
time: 1ms
memory: 5760kb

input:

5 5
0 1 0 0 1

output:

240

result:

ok single line: '240'

Test #6:

score: 5
Accepted
time: 0ms
memory: 6548kb

input:

5 3
0 0 0 0 0

output:

0

result:

ok single line: '0'

Test #7:

score: 5
Accepted
time: 0ms
memory: 6016kb

input:

39 39
1 0 1 0 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 0 1 1 1 1 0 0 1 0 1 1 0

output:

3958

result:

ok single line: '3958'

Test #8:

score: 5
Accepted
time: 0ms
memory: 5904kb

input:

45 34
0 0 0 1 1 0 1 1 0 0 0 0 1 0 0 0 1 0 1 1 1 0 1 0 1 0 0 1 1 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 1

output:

58701

result:

ok single line: '58701'

Test #9:

score: 5
Accepted
time: 1ms
memory: 6384kb

input:

62 62
1 1 1 1 0 1 1 0 0 0 1 0 0 1 0 1 1 0 1 0 1 1 0 0 0 0 1 0 1 0 0 0 1 1 0 1 1 1 1 0 0 1 0 0 1 1 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 1

output:

74689

result:

ok single line: '74689'

Test #10:

score: 5
Accepted
time: 0ms
memory: 6016kb

input:

9 3
0 0 0 0 1 0 0 0 0

output:

25739

result:

ok single line: '25739'

Test #11:

score: 5
Accepted
time: 0ms
memory: 6016kb

input:

503 503
1 1 1 0 1 0 0 1 1 0 1 1 0 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 1 1 0 1 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0 1 1 0 1 0 0 0 1 0 0 1 1 0 1 1 0 1 0 1 1 0 0 0 1 0 1 1 0 0 1 0 1 1 1 1 1 0 0 1 0 1 0 0 ...

output:

7933

result:

ok single line: '7933'

Test #12:

score: 5
Accepted
time: 0ms
memory: 6152kb

input:

962 658
0 0 0 1 1 1 0 0 1 1 1 0 0 0 1 0 0 1 1 1 1 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 0 1 1 1 0 1 0 1 0 0 0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 1 1 1 0 1 1 1 1 0 1 1 0 1 1 0 0 1 0 0 0 0 0 1 0 1 1 0 1 0 1 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 ...

output:

55348

result:

ok single line: '55348'

Test #13:

score: 5
Accepted
time: 0ms
memory: 6016kb

input:

724 724
0 1 0 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 0 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 0 1 1 1 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 0 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 0 1 0 1 1 1 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 1 1 1 1 1 ...

output:

69048

result:

ok single line: '69048'

Test #14:

score: 5
Accepted
time: 0ms
memory: 6016kb

input:

881 9
1 0 1 1 1 1 0 0 1 0 0 0 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 0 1 1 1 1 1 1 0 1 0 1 1 1 1 0 1 1 1 0 1 0 0 1 0 0 0 1 1 0 0 1 1 0 0 1 0 1 0 0 0 1 1 1 0 0 0 1 1 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 0 1 0 0 0 1 0 1 0 0 0 0 0 1 1 0 0 0 0 1 1 0 1 0 1 1 1 0 1 0 0 0 1 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 1 0 0 1 ...

output:

95266

result:

ok single line: '95266'

Test #15:

score: 5
Accepted
time: 0ms
memory: 6000kb

input:

668 668
1 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 1 0 1 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 0 1 0 1 1 1 0 0 0 1 1 1 1 1 0 1 1 1 1 0 1 0 0 0 1 0 1 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 1 1 1 0 1 0 0 1 0 1 1 0 0 0 1 1 0 ...

output:

33628

result:

ok single line: '33628'

Test #16:

score: 5
Accepted
time: 0ms
memory: 6036kb

input:

505 3
0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 1 1 0 0 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 1 0 1 1 0 1 0 0 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1 1 1 1 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 0 1 0 0 1 0 0 1 1 1 1 1 0 1 1 1 1 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 1 1 1 0 0 0 0 0 1 0 1 0 1 1 0 1 0 1 ...

output:

75577

result:

ok single line: '75577'

Test #17:

score: 5
Accepted
time: 3ms
memory: 6796kb

input:

8933 8933
0 0 1 1 0 0 0 1 1 0 1 1 0 0 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 1 1 0 1 1 0 0 1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 0 1 0 0 0 1 0 0 0 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1 1 0 1 0 0 0 1 0 1 1 0 0 0 1 0 0 1 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 1 1 1 0 0 0 0 0 0 ...

output:

31893

result:

ok single line: '31893'

Test #18:

score: 5
Accepted
time: 29ms
memory: 11520kb

input:

63525 7516
1 1 0 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 1 0 0 1 0 1 0 1 1 0 0 1 1 0 0 1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1 1 1 1 0 0 0 1 1 0 1 0 0 0 1 0 0 1 0 1...

output:

38712

result:

ok single line: '38712'

Test #19:

score: 5
Accepted
time: 24ms
memory: 11348kb

input:

64931 64931
1 1 0 1 1 1 0 0 1 0 1 1 0 1 1 1 0 1 0 1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 0 1 0 0 1 1 1 0 1 0 1 0 1 1 0 1 0 0 1 1 1 1 0 1 0 0 1 0 1 0 0 1 0 1 1 0 1 1 0 0 1 1 0 0 0 0 1 0 1 0 0 1 1 0 1 1 0 1 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 1 0 1 0 0 1 0 ...

output:

12510

result:

ok single line: '12510'

Test #20:

score: 5
Accepted
time: 36ms
memory: 14260kb

input:

96495 72757
1 0 0 1 1 0 0 0 1 0 0 1 0 1 1 1 1 1 0 1 0 1 0 0 1 0 1 1 0 1 0 1 1 1 1 0 0 0 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 1 1 1 1 0 0 1 0 1 0 0 0 0 1 0 1 1 0 0 1 1 0 0 1 0 0 1 1 0 1 0 0 0 0 1 1 1 0 1 0 0 0 1 0 0 1 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 1 0 1 1 0 1 1 0 0 1 1 1 1 1 0 1 0 0 0 0 1 0 1 0 1 ...

output:

71132

result:

ok single line: '71132'