QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#724764#7900. Gifts from KnowledgeThe_cosmosTL 10ms33840kbC++143.3kb2024-11-08 14:59:062024-11-08 14:59:07

Judging History

你现在查看的是最新测评结果

  • [2024-11-08 14:59:07]
  • 评测
  • 测评结果:TL
  • 用时:10ms
  • 内存:33840kb
  • [2024-11-08 14:59:06]
  • 提交

answer

// Problem: G. Gifts from Knowledge
// Contest: Codeforces - The 2023 ICPC Asia Jinan Regional Contest (The 2nd Universal Cup. Stage 17: Jinan)
// URL: https://codeforces.com/gym/104901/problem/G
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
using db = double;
using lb = long double;
using ull = unsigned long long;
using uint = unsigned int;
using ll = long long;
//using i128 = __int128;
//using ui128 = unsigned __int128;
#define REP(i, first, last) for(int i = (first); i <= (last); ++ i)
#define DOW(i, first, last) for(int i = (first); i >= (last); -- i)
#define int long long
#define pb emplace_back
#define ob pop_back
#define pii pair<int, int>
#define MPR make_pair
#define fi first
#define se second
#define tpl tuple<int, int, int>
#define MTP make_tuple
#define poly vector<int>
#define polyp vector<pii>
#define polyt vector<tpl>
#define all(x) x.begin(), x.end()
#define CVR(a, q) memset(a, q, sizeof a)
#define CLR(a) memset(a, 0, sizeof a)
#define CPY(a, q) memcpy(a, q, sizeof a)
#define PCT __builtin_popcount
const int N = 1.2e6 + 5, M = 1e6 + 5;
const int mod1 = 1e9 + 7, mod2 = 998244353, mod = 1e9 + 7;
const long long inf = 1e18;
const int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
const int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int r, c;
int sum[N], f[N << 1];
int find(int x) {
	if(f[x] == x) return x;
	return f[x] = find(f[x]);
}
int qpow(int x, int y) {
	int ans = 1;
	while(y) {
		if(y & 1) ans = ans * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return ans;
}
void Solve() {
	cin >> r >> c;
	poly a[N];
	REP(i, 1, r) {
		a[i].resize(c + 5);
		REP(j, 1, c) {
			char ch; cin >> ch;
			a[i][j] = ch - 48;
		}
	}
	REP(i, 0, max(r, c)) sum[i] = 0;
	REP(i, 1, c) REP(j, 1, r)
		sum[i] = sum[i] + a[j][i];
	REP(i, 1, c) if(sum[i] + sum[c - i + 1] > 2) return cout << 0 << '\n', void();
	// cerr << "qwq\n";
	REP(i, 1, r * 2) f[i] = i;
	// REP(i, 1, c) cerr << sum[i] << ' ';
	cerr << '\n';
	REP(j, 1, c) {
		if(j >= c - j + 1) break;
		if(sum[j] + sum[c - j + 1] < 2) continue;
		if(sum[j] == 2) {
			int u = 0, v = 0;
			REP(i, 1, r) if(a[i][j]) if(u) v = i; else u = i;
			int fu = find(u), fv = find(v + r);
			f[fu] = fv, fu = find(u + r), fv = find(v), f[fu] = fv;
		}
		else if(sum[c - j + 1] == 2) {
			int u = 0, v = 0;
			REP(i, 1, r) if(a[i][c - j + 1]) if(u) v = i; else u = i;
			int fu = find(u), fv = find(v + r);
			f[fu] = fv, fu = find(u + r), fv = find(v), f[fu] = fv;
		}
		else {
			int u = 0, v = 0;
			REP(i, 1, r) {
				if(a[i][c - j + 1]) if(u) v = i; else u = i;
				if(a[i][j]) if(u) v = i; else u = i;
			}
			int fu = find(u + r), fv = find(v + r);
			f[fu] = fv, fu = find(u), fv = find(v), f[fu] = fv;
		}
	}
	
	REP(i, 1, r) if(find(i) == find(i + r)) return cout << 0 << '\n', void();
	int ans = 0;
	REP(i, 1, 2 * r) if(find(i) == i) ans ++;
	// cerr << ans << '\n';
	cout << qpow(2, ans / 2) << '\n';
}
signed main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	int T = 1;
	cin >> T;
	while (T --) {
		Solve();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 10ms
memory: 33840kb

input:

3
3 5
01100
10001
00010
2 1
1
1
2 3
001
001

output:

4
0
2

result:

ok 3 number(s): "4 0 2"

Test #2:

score: -100
Time Limit Exceeded

input:

15613
10 10
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
15 8
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
1 5
00000
5 9
000000000
000000000
0000...

output:

1024
32768
2
32
32768
128
32
16
16
2
16384
16384
128
128
32768
8192
128
64
16384
2
4
2
4096
16
4096
1024
32768
32768
16384
8
128
2
16
4096
8192
32768
8192
8192
16
16384
16384
256
128
8
256
8
4096
512
2
4
32
32
2
64
512
1024
32768
32768
2
64
16384
16
8192
16
256
16
64
8192
8192
64
1024
2
32768
2
4
51...

result: