UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201021#315. nimAnonyme1001253ms5352kbC++111.4kb2024-01-18 09:06:572024-01-18 12:04:41

answer

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

#define QwQ330AwA return 0
#define ll long long

const int mod = 998244353;
int n, m;
int f[1 << 19];
int g[1 << 19];

void FWT(int *f, int op) {
	for (int mid = 1, len = 2; len <= (1 << m); mid <<= 1, len <<= 1) {
		for (int i = 0; i < (1 << m); i += len) {
			for (int j = 0; j < mid; j++) {
				int x = f[i + j], y = f[i + j + mid];
				f[i + j] = x + y;
				if (f[i + j] >= mod) f[i + j] -= mod;
				f[i + j + mid] = x - y;
				if (f[i + j + mid] < 0) f[i + j + mid] += mod;
			}
		}
	}
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	int sum = 0;
	for (int i = 1, x; i <= n; i++) {
		cin >> x;
		sum ^= x;
		f[x] = 1;
	}
	if (sum == 0) {
		cout << n;
		return 0;
	}
	m = 19;
	FWT(f, 1);
	for (int s = 0; s < (1 << m); s++) g[s] = 1;
	for (int i = 1; ; i++) {
		int fwt = 0;
		for (int s = 0; s < (1 << m); s++) {
			g[s] = 1ll * g[s] * f[s] % mod;
			if (__builtin_popcount(s & sum) & 1) fwt = (fwt - g[s] + mod) % mod;
			else fwt = (fwt + g[s]) % mod;
		}
		if (fwt) {
			cout << n - i;
			return 0;
		}
	}
	QwQ330AwA;
}
/*
  就是选一些数等于异或值,最小化选的个数
  答案不会很大,线性基最多只有logV
  就是异或意义下做卷积,枚举答案判断是否有那一位就可以
  O(2^nlognlogV)?
  哦单点求值用定义就好了
  O(2^nlogn)
 */

Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 12ms
memory: 5344kb

input:

7
451177 451177 451177 451177 451177 451177 451177

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 44ms
memory: 5344kb

input:

20
322529 220555 431510 314754 301609 280656 236091 370804 362081 217030 30854 191885 434633 232999 ...

output:

9

result:

ok single line: '9'

Subtask #2:

score: 20
Accepted

Test #3:

score: 20
Accepted
time: 9ms
memory: 5348kb

input:

100
45 20 55 48 54 57 3 49 85 11 89 22 72 40 32 93 34 16 97 32 93 38 49 60 20 15 89 20 0 75 52 45 95...

output:

99

result:

ok single line: '99'

Test #4:

score: 0
Accepted
time: 17ms
memory: 5344kb

input:

98
54 24 12 42 41 60 89 44 28 31 46 8 51 83 23 61 61 38 20 33 65 31 15 13 66 14 97 69 46 43 41 78 60...

output:

96

result:

ok single line: '96'

Test #5:

score: 0
Accepted
time: 21ms
memory: 5344kb

input:

86
60 91 91 91 60 91 65 60 68 60 68 91 68 65 60 68 68 91 91 60 68 68 60 91 65 91 60 91 91 68 91 65 9...

output:

82

result:

ok single line: '82'

Subtask #3:

score: 30
Accepted

Test #6:

score: 30
Accepted
time: 14ms
memory: 5348kb

input:

3000
2179 1555 484 2278 395 1924 2282 2449 1738 1402 1358 766 1332 1315 2027 221 993 2124 2589 2863 ...

output:

2999

result:

ok single line: '2999'

Test #7:

score: 0
Accepted
time: 17ms
memory: 5352kb

input:

2999
2687 840 2118 978 425 2398 2912 1799 2004 287 2908 1231 567 1620 463 1053 2688 2949 1835 2517 1...

output:

2997

result:

ok single line: '2997'

Test #8:

score: 0
Accepted
time: 20ms
memory: 5348kb

input:

2995
130 516 2890 130 130 130 130 130 130 2890 130 2890 130 516 1302 130 2890 516 516 130 516 2890 2...

output:

2990

result:

ok single line: '2990'

Subtask #4:

score: 40
Accepted

Test #9:

score: 40
Accepted
time: 8ms
memory: 1260kb

input:

214703
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

214703

result:

ok single line: '214703'

Test #10:

score: 0
Accepted
time: 70ms
memory: 5352kb

input:

250533
453748 447586 226267 53976 427330 431350 280082 383267 311954 55573 265152 275202 206100 4134...

output:

250532

result:

ok single line: '250532'

Test #11:

score: 0
Accepted
time: 75ms
memory: 5352kb

input:

300580
69900 194059 226853 335565 146266 92860 74119 236257 177385 130666 131727 276579 273876 36199...

output:

300578

result:

ok single line: '300578'

Test #12:

score: 0
Accepted
time: 44ms
memory: 5348kb

input:

24773
359366 495400 7368 145914 345494 45462 499951 237686 442568 493259 88294 93849 60961 329733 45...

output:

24771

result:

ok single line: '24771'

Test #13:

score: 0
Accepted
time: 92ms
memory: 5352kb

input:

499558
474671 188649 37326 326931 252637 443393 425194 406497 384571 13143 313795 369833 116352 3626...

output:

499556

result:

ok single line: '499556'

Test #14:

score: 0
Accepted
time: 90ms
memory: 5352kb

input:

499748
389184 151699 245879 426325 426187 273369 36341 199597 343887 313874 66954 56022 364855 42519...

output:

499747

result:

ok single line: '499747'

Test #15:

score: 0
Accepted
time: 100ms
memory: 5352kb

input:

499995
480816 171407 89002 63066 221315 221315 221315 221315 221315 221315 221315 163535 221315 2213...

output:

499982

result:

ok single line: '499982'

Test #16:

score: 0
Accepted
time: 91ms
memory: 5352kb

input:

499909
286388 275819 75501 275819 275819 275819 275819 275819 275819 70809 275819 361818 22079 36181...

output:

499898

result:

ok single line: '499898'

Test #17:

score: 0
Accepted
time: 73ms
memory: 5352kb

input:

499924
83714 160330 160330 241109 431991 160330 160330 160330 160330 160330 160330 160330 83714 4319...

output:

499918

result:

ok single line: '499918'

Test #18:

score: 0
Accepted
time: 53ms
memory: 5348kb

input:

499921
34058 34058 34058 34058 34058 34058 34058 34058 34058 34058 304319 34058 34058 34058 34058 34...

output:

499918

result:

ok single line: '499918'

Test #19:

score: 0
Accepted
time: 105ms
memory: 5352kb

input:

499943
47557 132388 208291 132388 47557 85123 47557 47557 47557 47557 208291 47557 47557 43009 13238...

output:

499928

result:

ok single line: '499928'

Test #20:

score: 0
Accepted
time: 117ms
memory: 5352kb

input:

499962
437784 283544 283544 283544 240538 362319 203588 455201 203588 283544 455201 283544 375120 28...

output:

499944

result:

ok single line: '499944'

Test #21:

score: 0
Accepted
time: 118ms
memory: 5352kb

input:

499982
91242 91242 91242 91242 36047 36047 433352 483264 394334 445589 367089 91242 281519 91242 912...

output:

499964

result:

ok single line: '499964'

Test #22:

score: 0
Accepted
time: 63ms
memory: 5352kb

input:

499979
295772 295772 300372 3811 295772 300372 3811 295772 3811 295772 3811 295772 3811 295772 3811 ...

output:

499976

result:

ok single line: '499976'

Extra Test:

score: 0
Extra Test Passed