P3857 [TJOI2008]彩灯 题解

O 看成了 0 调了一上午。

\(Solution\)

我们考虑用线性基来搞,然后有几个 \(P_i\),答案就是 \(2^x\)

/*
	Work by: TLE_Automation
*/
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define int long long
using namespace std;

const int N = 1e6 + 10;
const int MAXN = 2e5 + 10;

inline char readchar() {
	static char buf[100000], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
}

inline int read() {
#define readchar getchar
	int res = 0, f = 0;
	char ch = readchar();
	for (; !isdigit(ch); ch = readchar()) if (ch == '-') f = 1;
	for (; isdigit(ch); ch = readchar()) res = (res << 1) + (res << 3) + (ch ^ '0');
	return f ? -res : res;
}

inline void print(int x) {
	if (x < 0 ) putchar('-'), x = -x;
	if (x > 9 ) print(x / 10);
	putchar(x % 10 + '0');
}

int p[100], ans;

void Insert(int x) {
	for (int i = 63; i >= 0; i--) {
		if (x & (1ll << i)) {
			if (p[i]) x ^= p[i];
			else {
				p[i] = x;
				break;
			}
		}
	}
}

char s[MAXN];

signed main() {
	int n = read(), m = read();
	for (int i = 1; i <= m; ++i) {
		scanf("%s", s + 1);
		int x = 0;
		for (int j = 1; j <= n; ++j) if (s[j] == 'O') x |= (1ll << (j - 1));
		Insert(x);
	}
	int cnt = 0;
	for (int i = 60; i >= 0; --i) if (p[i]) cnt++;
	printf("%lld\n", (1ll << cnt) % mod);
	return 0;
}
posted @ 2022-05-22 11:06  TLE_Automation  阅读(32)  评论(0)    收藏  举报