QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#806#276998#7014. Rikka with Grid Graphsucup-team1005ucup-team1209Failed.2024-09-07 00:26:172024-09-07 00:26:18

Details

Extra Test:

Accepted
time: 1567ms
memory: 5912kb

input:

60
6 6
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
6 6
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
6 6
+-+-+-+-+-+
| | | | |...

output:

39931856138212664
39931856138212664
39931856138212664
39931856138212664
39931856138212664
39931856138212664
39931856138212664
39931856138212664
39931856138212664
39931856138212664
39931856138212664
39931856138212664
39931856138212664
39931856138212664
39931856138212664
39931856138212664
399318561382...

result:

ok 60 lines

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276998#7014. Rikka with Grid Graphsucup-team1209#AC ✓703ms6164kbC++202.2kb2023-12-06 14:18:102023-12-06 14:18:10

answer

#include<bits/stdc++.h>
using std::cin, std::cout;
using u64 = unsigned long long;
const int mod = 1e9 + 7;
const int N = 36;
int cc;
struct graph {
	u64 e[N];
	bool link(int x, int y) {
		if(e[y] >> x & 1) return 0;
		for(int i = 0;i < cc;++i) {
			if(e[i] >> x & 1)
				e[i] |= e[y];
		}
		return 1;
	}
	u64 gethash(const std::vector<int> & p) {
		u64 res = 0;
		for(int x : p) for(int y : p) res = res << 1 | (e[x] >> y & 1);
		return res;
	}
} G, EP;
int n, m;

int id(int x, int y) {
	return x * m + y;
}
int er[N][N];
int ed[N][N];
char buf[N];
std::vector<int> ids[N];
std::vector<int> edge[N];

std::map<u64, u64> map[N];
u64 dfs0(int x, graph g) {
	if(x == cc) return 1;
	u64 z = g.gethash(ids[x]);
	auto iter = map[x].lower_bound(z);
	if(iter != map[x].end() && iter -> first == z) {
		return iter -> second;
	}
	u64 res = 0;

	for(int i = 0;i < 1 << (int) edge[x].size();++i) {
		graph tmp = g; int ok = 1;
		for(int j = 0;j < (int) edge[x].size();++j) if(i >> j & 1) {
			ok = ok && tmp.link(x, edge[x][j]);
		} else {
			ok = ok && tmp.link(edge[x][j], x);
		}
		if(ok) res += dfs0(x + 1, tmp);
	}

	map[x].emplace_hint(iter, z, res);
	return res;
}

int main() {
	int T;
	scanf("%d", & T);
	for(int i = 0;i < N;++i) EP.e[i] |= 1ull << i;
	for(int i = 0;i < T;++i) {
		memset(er, 0, sizeof(er));
		memset(ed, 0, sizeof(ed));
		scanf("%d %d\n", &n, &m);
		for(int i = 0;i < n;++i) {
			memset(buf, 0, sizeof(buf));
			fgets(buf, sizeof(buf), stdin);
			for(int j = 0;j + 1 < m;++j) {
				if(buf[j * 2 + 1] == '-') {
					edge[id(i, j + 1)].push_back(id(i, j));
				}
			}
			if(i + 1 < n) {
				memset(buf, 0, sizeof(buf));
				fgets(buf, sizeof(buf), stdin);
				for(int j = 0;j < m;++j) {
					if(buf[j * 2] == '|') {
						edge[id(i + 1, j)].push_back(id(i, j));
					}
				}
			}
		}
		for(int i = 0;i < n;++i) {
			for(int j = 0;j < m;++j) {
				std::vector<int> & v = ids[id(i, j)] = {};
				for(int k = 0;k < j;++k) v.push_back(id(i, k));
				if(i) for(int k = j;k < m;++k) v.push_back(id(i - 1, k));
			}
		}
		cc = n * m;
		u64 ans = dfs0(0, EP);
		for(int i = 0;i < cc;++i) map[i].clear(), edge[i].clear(), ids[i].clear();
		cout << ans << '\n';
	}
}