QOJ.ac

QOJ

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

Judging History

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

  • [2023-12-06 14:18:10]
  • 评测
  • 测评结果:AC
  • 用时:703ms
  • 内存:6164kb
  • [2023-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';
	}
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
2 2
+-+

+ +
2 2
+-+
|
+ +
2 2
+-+
|
+-+
2 2
+-+
| |
+-+

output:

2
4
8
14

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 703ms
memory: 6164kb

input:

60
1 1
+
6 6
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
| | | | | |
+-+-+-+-+-+
6 4
+ + + +

+ + + +

+ + + +

+ + + +

+ + + +

+ + + +
4 5
+-+-+-+ +
|       |
+-+-+-+ +
  |     |
+-+ +-+ +
| |
+ + +-+ +
5 6
+ + +-+ + +
| | |   | |
+-...

output:

1
39931856138212664
1
32768
2097152
396928
1912140726272
17072685056
33681342464
1070508371744
4877910016
470169766912
181121759168
814322432
891691528874048
358663151840
1905966526844408
851738327552
191458384162304
288115586432
1368156669845336
356038587648896
3776487925133468
691176008890304
1090...

result:

ok 60 lines