QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#397202#8114. Labirintlfxxx#11 2ms4388kbC++141.8kb2024-04-23 19:33:402024-07-04 03:37:05

Judging History

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

  • [2024-07-04 03:37:05]
  • 评测
  • 测评结果:11
  • 用时:2ms
  • 内存:4388kb
  • [2024-04-23 19:33:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
bool be;
constexpr int N = 105;
int n, m, a[N][N], b[N][N];
struct dsu {
	int fa[N * N];
	dsu() {
		iota(fa, fa + N, 0);
	}
	int find(int k)
	{
		return fa[k] == k ? k : fa[k] = find(fa[k]);
	}
	void merge(int u, int v)
	{
		u = find(u), v = find(v);
		if (u == v) return;
		fa[u] = v;
	}
}d[16];
int to(char c)
{
	if (c == 'P') return 0;
	if (c == 'C') return 1;
	if (c == 'Z') return 2;
	return 3;
}
int id(int i, int j)
{
	return (i - 1) * m + j;
}
bool en;
int main()
{
#ifdef IAKIOI
	freopen("in.in", "r", stdin);
//	freopen("out.out", "w", stdout);
	cerr << (&be - &en) / 1024.0 / 1024 << " MB\n-------------------\n";
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j < m; ++j) {
			char c;
			cin >> c;
			a[i][j] = to(c);
		}
	}
	for (int i = 1; i < n; ++i) {
		for (int j = 1; j <= m; ++j) {
			char c;
			cin >> c;
			b[i][j] = to(c);
		}
	}
	for (int S = 0; S < 16; ++S) {
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j < m; ++j) {
				if ((S >> a[i][j]) & 1) {
					d[S].merge(id(i, j), id(i, j + 1));
				}
			}
		}
		for (int i = 1; i < n; ++i) {
			for (int j = 1; j <= m; ++j) {
				if ((S >> b[i][j]) & 1) {
					d[S].merge(id(i, j), id(i + 1, j));
				}
			}
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int a, b, c, D;
		cin >> a >> b >> c >> D;
		int x = id(a, b), y = id(c, D), ans = 5;
		for (int S = 0; S < 16; ++S) {
			if (d[S].find(x) == d[S].find(y)) {
				ans = min(ans, __builtin_popcount(S));
			}
		}
		cout << ans << '\n';
	}
	return 0;
}

详细

Subtask #1:

score: 11
Accepted

Test #1:

score: 11
Accepted
time: 1ms
memory: 3628kb

input:

1 100
NPPPZNNPCPCNZNZNZPZZPPPNPCPNPZCPCPCNNCZZPPCPPZPNPNCZCPZNZNPPZNPPZZNPPNCNPZZPZPZZNPCPNNZNNPCNCPZPCNN
100
1 55 1 37
1 52 1 64
1 36 1 4
1 68 1 66
1 50 1 80
1 84 1 77
1 99 1 68
1 84 1 56
1 5 1 95
1 38 1 68
1 82 1 3
1 64 1 36
1 61 1 21
1 1 1 4
1 2 1 46
1 55 1 100
1 4 1 83
1 53 1 96
1 76 1 43
1 21 1...

output:

4
4
4
2
4
4
4
4
4
4
4
4
4
2
4
4
4
4
4
1
4
4
4
4
3
4
4
4
2
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
1
4
4
4
4
4
4
4
4
2
4
4
4
4
4
4
4
4
4
4
4
4
3
4
4
2
4
4
4
2
4
4
4
4
4
4
3
4
4
4
4
3
4
4
4
4
3
4
1

result:

ok 100 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

1 100
NPNPZPCZZPPCCNCZNPPCCZNNPPPZCCCCPZZPCZPZPPPPNCPCZPCPZZZPCCZZCPPCCNPNCZCNZPCNZNCCPZZZZZZCNZCNNPNPZCC
100
1 36 1 54
1 36 1 56
1 35 1 3
1 21 1 96
1 18 1 37
1 55 1 86
1 90 1 91
1 90 1 99
1 17 1 42
1 53 1 72
1 5 1 61
1 91 1 29
1 69 1 62
1 78 1 53
1 36 1 47
1 37 1 16
1 90 1 14
1 83 1 15
1 7 1 48
1 4...

output:

4
4
4
4
4
4
1
4
4
4
4
4
3
4
4
4
4
4
4
4
4
1
4
4
4
4
4
4
2
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
2
4
4
4
4
3
4
4
4
4
4
4
1
4
4
4
4
4
2
4
4
4
4
4
4
4
4
4
4
4
4
4
2
1
2
4
4
4
3
4
4
3
2
4
4
4
4
4

result:

ok 100 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

1 100
CCPCPPZNNNZPZNCCCPPZNCCCPPPPCNNPZZCCCZCNPZNCNPZCNPNPNNCNPCZPNNCZZZPCNZNPCPZCPNZZZPNCNNZNNNNPNNZCNPN
100
1 81 1 78
1 80 1 50
1 32 1 94
1 100 1 50
1 27 1 25
1 47 1 94
1 52 1 20
1 21 1 72
1 38 1 28
1 3 1 33
1 20 1 33
1 60 1 78
1 62 1 34
1 48 1 49
1 91 1 36
1 94 1 36
1 15 1 55
1 20 1 98
1 81 1 97
...

output:

2
4
4
4
1
4
4
4
4
4
4
4
4
1
4
4
4
4
4
4
4
4
4
4
1
4
4
4
4
4
4
4
4
4
4
1
4
4
2
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
2
4
4
4
4
4
3
4
4
4
4
4
4
4
4
4
2
1
4
4
4
4
4
4
3
4
4
4
4
4
4

result:

ok 100 lines

Test #4:

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

input:

1 100
NNPNNCCZPPCNCCPCCPZCCPZZCZZCPNNNNCNPCNCNCCPCCZPZPPZZPZCPZPZCCCZNCZCNZCCCZCNCCZPPPPCZNNCPNZNZNNCCNPZ
100
1 99 1 21
1 71 1 64
1 13 1 25
1 20 1 94
1 84 1 20
1 29 1 22
1 79 1 34
1 28 1 46
1 87 1 59
1 3 1 64
1 54 1 69
1 63 1 47
1 33 1 59
1 94 1 100
1 99 1 18
1 88 1 30
1 21 1 56
1 30 1 26
1 49 1 92
...

output:

4
3
3
4
4
3
4
3
4
4
4
3
4
4
4
4
4
3
4
4
4
4
4
4
4
3
4
4
4
4
4
4
3
4
4
4
3
4
4
2
4
3
1
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3
3
4
4
4
2
4
4
2
3
4
4
4
3
3
4
4
4
4
2
4
4
4
2
1
1
2
4
2
4
4
4
4
4
4
4
3
4
4
4
4
4
3

result:

ok 100 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3728kb

input:

1 100
ZCNPNPNCZPPNZZNPNNCPNZNPPPZNNZZPNNPCZNNNNNPZZPPZNCNCNPPZCNNPNPCPNCNCCNNZPZNCPPZCCPCZCCNPPCCPCZZCZZZ
100
1 9 1 55
1 80 1 51
1 97 1 85
1 74 1 92
1 68 1 24
1 73 1 97
1 2 1 82
1 18 1 94
1 70 1 94
1 74 1 8
1 11 1 91
1 9 1 8
1 58 1 85
1 55 1 74
1 28 1 75
1 74 1 63
1 35 1 67
1 77 1 59
1 97 1 32
1 63 ...

output:

4
4
4
4
4
4
4
4
4
4
4
1
4
4
4
4
4
4
4
4
4
4
4
4
1
4
4
4
4
4
4
4
4
4
4
4
2
4
1
3
4
4
4
4
4
4
4
3
4
4
2
4
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
1
3
4
4
4
4
4
4
4
1
4
4
4
4
4
4
4
4
4
2
4
4
4
1
4
4

result:

ok 100 lines

Test #6:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

1 100
PCPNNNPNCPZNNZCPZZPCCNZPPCNZNPZPPPCZPNCZPCNPCCZPZCNCZCNCNZPNCZCNPZPPNCNCZNPCNZNNZCPNCZNNNPZNZPCPPCC
100
1 11 1 34
1 70 1 64
1 1 1 82
1 95 1 96
1 42 1 85
1 27 1 18
1 87 1 48
1 59 1 9
1 30 1 26
1 22 1 58
1 43 1 72
1 33 1 29
1 89 1 60
1 99 1 89
1 55 1 24
1 18 1 9
1 26 1 54
1 57 1 18
1 30 1 37
1 6...

output:

4
3
4
1
4
4
4
4
3
4
4
3
4
4
4
4
4
4
3
4
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
2
2
4
4
4
4
4
4
1
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3
4
4
4
4
4
4
4
4
1
4
4
4
4
4
1
4
4
4
4
4
4
4
4
4
4

result:

ok 100 lines

Subtask #2:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 1ms
memory: 4320kb

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

0
1
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
0
0
1
0
0
0
0
0
0
0
0
0
1
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

result:

wrong answer 1st lines differ - expected: '2', found: '0'

Subtask #3:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 2ms
memory: 4364kb

input:

100 100
PPPPCCCCCCCCCPCCPPCCCPPPCCPPCCCPPPPPCCCCCCCPCCCPCCPPCCCPPCCCPPPCPPPPPPCCPPPCCCPPCCCCCPPPPPPPPCPPCPC
PCPCPCCCCCCCPPPCCPPPPPPCPPPCPCPCCPPPCPCPCCPCCCCCCPPPCCPCCPCPCCPPCPPCCPCCPPPCPPPCPPCPCPPPCPCPPCPCCCC
PCPCCCPPCPPPPCCCCCPCPPCCPPPPPCCCPCPPPPPPPCCPPCCPPCCPCCCCCPPCCCPPCPCPPCCPCPCPCPPPPCCPPPPCCPCP...

output:

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
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
0
0
0
0
0
0

result:

wrong answer 1st lines differ - expected: '2', found: '0'

Subtask #4:

score: 0
Wrong Answer

Test #25:

score: 0
Wrong Answer
time: 2ms
memory: 4388kb

input:

100 100
PZCZZZNPZPZPCCCCPNPZCCZZPPPPNCPZNPZPPNZNCPCNPCNCZZNCCZPZPPPZZZCZCZNPZPNZZZPPZPPZZPCPCZPNNCZZCPCNNNZ
NCZZPPCZNZNNNNNNPPNNCPZCZNNPNCCPZZZCZNPZZZNCCNNZPPCPZNPCPCZCZPZCCPPPCZPZCCPNNNNZZZZCZZNZNZPPZPCNZPC
PCCNZCCZZPZPPNZZNPCCNNZPCNPPZZNCPZNZPCZZPPCCCCNNZZCCNPPZNZNZZZNNNNZZNCNCCCNZPCZCPPZPCPCPZNPP...

output:

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
1
0
0
0
0
0
0
1
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
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

wrong answer 1st lines differ - expected: '3', found: '0'