QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397213#8114. Labirintlfxxx#70 ✓3ms4592kbC++141.8kb2024-04-23 19:44:182024-07-04 03:37:11

Judging History

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

  • [2024-07-04 03:37:11]
  • 评测
  • 测评结果:70
  • 用时:3ms
  • 内存:4592kb
  • [2024-04-23 19:44:18]
  • 提交

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 * 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;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 11
Accepted

Test #1:

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

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: 4516kb

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: 4520kb

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: 1ms
memory: 4228kb

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: 1ms
memory: 4284kb

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: 1ms
memory: 4480kb

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: 13
Accepted

Test #7:

score: 13
Accepted
time: 0ms
memory: 4300kb

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

2
2
2
2
2
1
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #8:

score: 0
Accepted
time: 1ms
memory: 4384kb

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #9:

score: 0
Accepted
time: 1ms
memory: 4376kb

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #10:

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

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #11:

score: 0
Accepted
time: 1ms
memory: 4384kb

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #12:

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

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP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
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2

result:

ok 100 lines

Subtask #3:

score: 24
Accepted

Test #16:

score: 24
Accepted
time: 3ms
memory: 4396kb

input:

100 100
PPPPCCCCCCCCCPCCPPCCCPPPCCPPCCCPPPPPCCCCCCCPCCCPCCPPCCCPPCCCPPPCPPPPPPCCPPPCCCPPCCCCCPPPPPPPPCPPCPC
PCPCPCCCCCCCPPPCCPPPPPPCPPPCPCPCCPPPCPCPCCPCCCCCCPPPCCPCCPCPCCPPCPPCCPCCPPPCPPPCPPCPCPPPCPCPPCPCCCC
PCPCCCPPCPPPPCCCCCPCPPCCPPPPPCCCPCPPPPPPPCCPPCCPPCCPCCCCCPPCCCPPCPCPPCCPCPCPCPPPPCCPPPPCCPCP...

output:

2
1
1
1
2
1
1
2
2
2
2
2
1
2
1
1
2
2
2
2
2
1
1
1
1
1
1
1
1
2
2
2
2
1
1
2
1
1
2
2
2
2
2
1
2
1
2
1
2
2
1
1
2
2
1
1
1
1
2
1
1
1
1
1
2
1
1
2
2
2
2
2
2
1
1
1
2
2
2
1
2
1
1
2
1
2
2
1
2
2
1
2
2
2
2
1
2
2
2
1

result:

ok 100 lines

Test #17:

score: 0
Accepted
time: 3ms
memory: 4388kb

input:

100 100
PPPPPCCPPCPCPPPCPCCPPPPCPCCCPPCPPCCCPPCPCCPPCPCPCCCPPCPPCCPPPPCCCPCCCCCCCCPPCCPPPCCCPPPCCPCCPPCCPPP
CCPCPPPPCPPCCPCCCCCCPPCCPCPCCCCCPCCPPPPCPCPPCPCPCCPCPCCPCPPCPPCPPPCPCCCPCCPCPPPPPPPPPPPPCCCPCCPCCCP
PPPPPCCCPPPCPCCCPPCPCCPPPCPPCCPCCCCPCCPPPCPPCPCCPPCCCCCPCCPCPCPPCPPPPCCPPCPCPCPCCPCCPPCCPPPC...

output:

1
1
2
2
2
1
2
1
1
1
2
1
1
2
2
1
2
1
2
1
1
2
2
2
2
1
1
2
1
1
2
2
1
1
1
2
1
2
2
2
1
1
2
2
2
2
1
1
2
2
1
2
2
2
2
2
2
1
1
2
2
2
2
2
2
2
2
2
2
1
2
2
1
2
2
2
1
1
2
2
2
2
1
2
2
2
1
2
1
2
2
2
2
1
2
2
1
2
1
2

result:

ok 100 lines

Test #18:

score: 0
Accepted
time: 3ms
memory: 4532kb

input:

100 100
PPPPPPCPCCPPCCCPPCCCPCPPCCCPPPPPCPCPCCCPCCCPPPCPCPPPCPPPCCPPCCPCPCPCCPCPCCPPPCPPCCCPCPPCCCCCPCPPPCC
PCCPCPCPPCCCCPCPPCCCCCCCCCCPPPCPCCCPCPCCCCPPCCCCCCPPPCPCCCPCPPPPPPCPCCPPCPCCCPPCPCCCPPPPCPCPCCPPCCC
PCCPCCCPCCPPCPCCCPCPCPPCCCPCCPPCPPPCCCCCCCPPPPPCCCCPPCPPCPPPCCCCCPPPCPCCPPCCCCCPCPPCPCCPPPCC...

output:

2
1
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
1
2
2
2
2
1
1
1
2
2
2
2
2
2
1
2
2
2
2
1
1
1
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #19:

score: 0
Accepted
time: 3ms
memory: 4556kb

input:

100 100
PCCCCPPPPPPPPPPCCPPPCCPCPPPPPPPCPPCPPCCCPCPCPPPCPPPPCPPCPCPPPCCPPPCPPPPCPCPPPPPPPCCPPCCPPCCCPPPPCCC
PCCPCPPCPCCCCPCCCCCPCPPCPPCPCPPPCPPCPCPCPPCCCPCCPPPCPPCCCPPCCPCPPCPCCPPCCPCCPPCCPPCCPPCPCPCPPPCPCCC
CCPCCPCCPCPCCPPPPCPCCPCCPPCPCCCCPCPPPPCPCCPPCPCCCCPPPCCPPPCCPCPCCPCPPPCPCPCPCCPPPPCPPCCPPCPP...

output:

2
2
2
2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PPPPPPPPCPCPPCCPCCCPPPCPPCCCPCPPCPCPPPPCPPCPPPPCPPPCCCPCCC...

output:

2
1
1
1
1
2
1
1
2
2
1
1
2
2
2
1
2
1
1
2
2
1
1
1
2
2
1
1
2
1
2
1
1
2
1
1
1
1
1
2
1
2
1
1
1
1
1
2
1
1
1
2
1
1
1
1
1
2
1
2
1
2
1
1
2
1
1
2
1
1
2
2
1
2
1
2
1
1
2
1
1
2
1
2
1
2
1
2
1
1
1
2
2
2
1
2
2
1
2
1

result:

ok 100 lines

Test #22:

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

input:

100 2
C
C
C
C
P
P
C
P
P
P
C
C
P
C
C
C
C
P
P
P
C
P
P
C
C
C
C
P
C
C
P
C
P
P
P
C
C
P
C
P
P
P
P
P
C
C
P
P
P
P
P
P
P
P
P
C
C
C
P
C
P
P
P
C
P
C
C
C
P
P
P
C
C
P
C
P
P
P
C
C
P
P
C
C
P
P
P
P
C
C
C
C
P
C
C
P
P
P
P
C
CC
CC
PP
PC
CP
CP
PP
PP
PC
PC
CC
PC
CC
CP
CP
CP
PC
PC
PP
CP
CC
CP
CC
PP
CC
PP
PC
CC
PC
CP
CP
P...

output:

2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
1
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #23:

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

input:

100 10
PCPCCCPPP
CPCPCPPCC
PPPPPPPPP
CPPPCPCPC
PPPPPCPPP
CCCPCPCPP
CPCCCCPPC
CPCCPCPPP
CCPCPCCPC
PCPPPPCCP
CPCCPCCCC
PPPCPCPCP
CCPPCCCPP
CPCPCPPCP
CPCPPCPPP
PPPPPPCCC
PCPCCPPPC
PPPPCPPPP
PCCPCPPCP
PPCPCPCCC
PCCCCCCCC
PPCCPPPCC
CPPCPPPPP
CCPCCPPCP
CPCPPPPCP
PPPCPPPCC
CPPPCCPPC
PCCCPPCCP
CPCPPPPCP
CCC...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
1
2
2
2
2
2
1
2
2
2
2
1
2
2
1
2
2
2
1
2
2
2
1
2
2
1
2
2
1
2
2
2
2
1
2
1
1
2
2
2
2
2
1
2
2
1
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #24:

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

input:

10 100
PCPCCCCPCPPCCCCPCPPCCCPPCPPCPPPPPCCPPCPCPCPPPCPPPCCCPCPPPPCPPPCPCCCPCCPPCPPCCPCPCCCCPCPCPCCCCCCPPPP
PPPCPPCPPCPCPPPCPPPPPPPPPCCCPPPCCCCPCCCCPPCPPPCCCPPPCPCCCPCPPPPCPCCCCPPPPCCCCPPCCCCCPPPPPPCPCPPPPPC
CCCCPCPCPPPCCCPCPPCPCPPPCPCCCPCPCCPPCCPCPCCCPCCCPPPCCPCPCPPCCCPCCPCPPCPCPCPPCPCPCPCPCCCPCCPCC...

output:

2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
1
2
2
2
2
2
2
1
1
2
2
1
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
1
2
2
2
2
2
1
2
2
2
2
2
2
1
2
2
2
2
2
2
2
1
2
1
1
2
2
2
1
2
2
2
2
2
2
2

result:

ok 100 lines

Subtask #4:

score: 22
Accepted

Test #25:

score: 22
Accepted
time: 0ms
memory: 4592kb

input:

100 100
PZCZZZNPZPZPCCCCPNPZCCZZPPPPNCPZNPZPPNZNCPCNPCNCZZNCCZPZPPPZZZCZCZNPZPNZZZPPZPPZZPCPCZPNNCZZCPCNNNZ
NCZZPPCZNZNNNNNNPPNNCPZCZNNPNCCPZZZCZNPZZZNCCNNZPPCPZNPCPCZCZPZCCPPPCZPZCCPNNNNZZZZCZZNZNZPPZPCNZPC
PCCNZCCZZPZPPNZZNPCCNNZPCNPPZZNCPZNZPCZZPPCCCCNNZZCCNPPZNZNZZZNNNNZZNCNCCCNZPCZCPPZPCPCPZNPP...

output:

3
2
3
3
3
2
2
3
2
2
2
3
2
3
2
2
2
2
3
3
3
3
2
3
2
3
2
3
2
2
2
3
2
3
2
2
2
2
2
2
3
2
2
2
2
2
3
2
2
2
2
3
2
2
2
3
2
2
2
3
3
2
2
2
2
2
2
2
3
2
3
2
2
2
2
2
2
3
2
2
3
3
3
2
2
3
2
2
2
3
2
2
2
2
2
2
2
2
3
3

result:

ok 100 lines

Test #26:

score: 0
Accepted
time: 3ms
memory: 4304kb

input:

100 100
CCPNZPZCNNCNPCZPCPNCNNCZZCNPNCCZCCCPZCCPPNPCPZZPPZNNCPZPPZZPZCZNNPZCNPNPZPCCZCNZNCCCZZPZCZNPCCCZNPP
CZCPZZNCZZPNNCNZZCZZNNNNNZNCZZPCNNPNCPCZCZCCZPPCNPNPPNCPZZCNPZCZZCZZZNPZPCPCCCZPNPCCNNPCNPNNPPZCCPN
CCCCZPPNPNNCNPZCZCPPNCCNZPPNCNZNZNNPNZZPZCNZPZCNNPPZPNZPNZZCCPZCCZZZPPCZZZCZZCZNZCZCNCNPZPZC...

output:

3
2
2
2
3
2
2
2
3
2
2
2
2
2
3
2
3
2
2
2
3
3
2
2
3
3
2
2
2
2
3
3
2
2
2
2
2
2
2
3
2
2
2
2
2
3
2
2
2
2
3
3
2
2
3
2
2
2
2
3
2
2
2
3
3
2
2
3
2
2
2
3
3
2
3
3
3
2
2
2
2
2
3
3
2
2
2
2
2
2
2
2
2
3
3
2
2
2
2
3

result:

ok 100 lines

Test #27:

score: 0
Accepted
time: 3ms
memory: 4304kb

input:

100 100
P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
2
3
3
2
2
2
2
3
3
3
2

result:

ok 100 lines

Test #29:

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

input:

100 100
ZZPCPPPPNZPNNZNZNCZZPPCZPNPPCZPPZNCZPPCNPNCNPZNZCCNZPPCCPPZZZZPPZPCPCPCCZCPNPCZNCZPPZPPZPCCNCZPNZCC
ZZCCCZZPCZCZNZPCPZPCZZPNCNPNCNNNCPCNZNPCZNCNPPZPNNNZCPCPZPNPZNZCNNZPZCNZNPPNPPNNNCNNPZPNCZNPPZPZPCP
CCPZNPPZZNNCPPPCNCZCZPPZCNCCCCPZCCPCNCPPCPPCPCPCPPNZPCPNNCPZZNZZPCZNCCNPCCZZNPCPZNNNPCPZNNPC...

output:

2
3
2
3
3
2
3
3
3
3
2
3
2
2
2
2
2
3
2
2
3
2
2
3
3
2
3
3
3
2
2
3
2
2
2
3
3
2
2
2
2
2
3
2
2
2
2
2
2
2
3
3
3
2
2
2
2
2
2
3
3
3
3
3
2
2
2
2
3
2
2
2
2
2
3
3
3
2
2
2
3
2
3
3
2
2
3
3
2
2
2
2
2
2
2
2
2
2
2
3

result:

ok 100 lines

Test #30:

score: 0
Accepted
time: 3ms
memory: 4304kb

input:

100 100
CZNPPZPZPCNZZCCPPZZPNNPCCZPCPCNCZPPCPPNCZNCZCCCZPPCNZPNPZCNPZNPPPPZZZZPNCZPNPNNNZZCCPPNPZNPPZCNCZPN
ZNCPPZCZPCNPNCCCPZNCCNNPPPCNPZCCZZZCNCNZZCPZPNNPPCPPCNZZZZPNPNPZZCPPNNCNCZZNZZPPZZPPCPZNPNPNZPPPZCN
NCNNNPZCCZZNZCCNZZNCZPNZCCNNZPCZZZNZPPZZNZCPNZPCZNPPPZNNZCZNZNPNPCCPPPPNCZNCPPPZCNCNNCZNPPCZ...

output:

3
3
3
3
3
2
3
2
2
3
2
3
3
3
3
3
3
3
3
2
2
2
2
3
3
3
2
3
2
2
2
3
2
3
3
2
2
2
3
2
3
3
3
2
3
2
2
2
2
2
2
3
2
3
2
2
3
3
2
2
3
2
2
2
3
2
2
2
2
2
2
3
2
2
3
2
2
2
2
2
3
3
2
3
2
2
3
2
3
2
2
2
2
2
3
2
3
3
3
2

result:

ok 100 lines

Test #31:

score: 0
Accepted
time: 3ms
memory: 4524kb

input:

100 100
CCCCPPCPNCCZCZNPPPNCZPNNCPZPNCCPPZCPNPZPCNPPCPPZNNPCPCZPCCPZPZZZZCPNCZNNPZCCNCZPCZZPNZNCPZPZPZNNPNZ
ZPZZCCCNZPPCZCPNCCNCPPCZCNZCNPCCNZCPPNZNZCZZZNCCCPZCZPPZNPZNZNPNNPZNCPNNZCZPCZCZPCCNPCNCNNNZPCNZZCC
CPNZCPNPNPPCCZPNZNNCNNZNZPNCZCZPNCNZCCCNPNNZNNCPNNPCZPNPCNPPCNCNZNZZNCNCNPNPCCPZCNPCCCCNPNPC...

output:

2
2
2
2
2
3
2
3
2
3
3
2
3
2
2
2
2
2
2
2
2
2
3
2
2
2
2
3
2
2
2
3
2
3
3
3
3
3
2
2
2
3
3
2
3
2
3
2
2
2
2
3
2
2
2
2
2
3
3
2
3
2
2
3
2
2
3
2
3
3
3
2
3
2
3
2
2
3
3
2
2
2
2
2
3
2
3
3
2
2
3
3
2
3
2
2
2
3
3
3

result:

ok 100 lines

Test #32:

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

input:

100 100
CZPNPZPZNPPCZPZPNPCNZPZPPPPCCNNCCPCZCZNNZNPPNNNZCNNPCNNZNCCZNNNNZZCPNPNPNNZNZZZNZZCPZPZZCZNCCCPNNCZ
CPPCNNCNCNCNPCCNNCPNZCZZZCNPCZPCCPPZCPPPNNNPNNNCNCZCCCCCPNZPPCCNZNNPPNCPZCCNCZPNNPZZCCNZPPNNZZPZCCP
NCNNCNNPCNZPNPCZPZZPZPNZPNPZNPNZPZPPCCCPCZCNCZCZCNNCCPZPZNCPCZPNPPZPZPNCCCZCNPPPPCNPZZNZZPPC...

output:

2
3
3
2
3
3
2
2
3
2
2
2
3
2
3
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NZPNPCZCNZPZZZCZZPPNNNNZNCNZZZCZZPPZN...

output:

3
3
2
2
2
3
2
3
3
3
3
2
2
2
2
2
3
2
2
2
3
3
2
3
2
2
2
3
2
2
2
2
2
2
2
3
3
3
3
3
3
3
3
2
2
2
3
2
3
3
2
2
3
2
2
2
2
3
2
2
3
3
3
2
2
2
3
2
3
3
3
2
2
2
2
2
3
2
3
2
3
3
3
2
3
2
3
3
2
3
3
2
2
3
3
3
3
3
3
3

result:

ok 100 lines

Test #35:

score: 0
Accepted
time: 1ms
memory: 4220kb

input:

10 100
NNNCPZNZNNNCZPPCZZCNNNCNZZNPCCZZNCCPZNZZPCCNZNZCZCCZPNPCZCNCCCCNNZZZZCPPNZPZZZPNPCPNZCNNZZPCZZCPZCZ
NNNCZPZNNZCCCPZCCPZZCCPZCCPNZCCPCNPPCCZPCCPPNNNPNZNPPNPNPPCCNPNPNNNPNCNZZCPCNPZPPCZPNPNCNPCPCPCCZZN
PCPPNPZZPZNZNZPPPCPZNPNZPPPCNNPCCCCPZNNZZCCZNNPCNNNZPPZPNPZNCNZZPZCPPZPCCZNNZCZNZNCNPZZCPZZZP...

output:

2
2
1
3
3
3
2
3
3
3
2
3
3
2
2
3
3
2
3
2
2
2
2
3
3
3
3
3
3
2
2
3
3
3
2
3
3
3
3
3
3
2
2
2
3
3
2
2
3
3
2
3
2
3
3
3
3
2
3
3
3
3
2
3
3
3
2
2
3
3
3
3
2
3
3
3
3
2
2
2
2
2
3
3
2
3
2
2
3
2
3
3
2
3
2
2
3
3
2
3

result:

ok 100 lines

Test #36:

score: 0
Accepted
time: 1ms
memory: 4240kb

input:

20 100
ZNPPZPPCZZCPZPNNNPPNNNCPCPNZZPZCZZPNZCNZCCNCNZNPCCCCPNZPNNNCZCNZZCNPZPCZZCPPPNZCNNZNPPCNPZPCPCPPZZP
ZZNPNNZPZPCCNNPZCNNNNZZZNZZPNCPCCPZZCNPZZCCNPPPPNZZCZCCCCCNPNNPNPCCPNCPZCPNZCNZPZZPCZNPCNCNNPPPCCZP
CZZCNCCCNCCCCZCCZPCCPCZPPZCNPNZZCZZNCNCCZCZPPCPZCPPZPZZCCNZNPCNPNPPCCNZZPCNCCCNNCCZZPCPNZNCZN...

output:

3
2
3
2
3
3
3
3
3
2
3
3
2
3
2
3
2
3
2
2
3
2
2
2
2
2
3
2
3
3
3
2
2
2
2
2
2
2
2
2
2
2
2
3
2
3
2
2
2
3
2
3
3
2
2
3
3
2
2
2
3
3
2
2
2
2
2
3
2
2
3
3
2
2
2
3
2
2
3
3
2
2
2
2
2
2
2
3
2
3
3
3
3
2
3
2
2
2
3
3

result:

ok 100 lines

Test #37:

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

input:

30 100
NZCNPNNZZCCZPPPNNNCPCZCNCCCZPNPNNPPPPZCPNCZCZNZPCZCNZPNPCCCZPCZCPPNZNCCNZNZPZZNCPPZNCCPZPNPNNNPCCCP
NPPCPPZPZNNNPCPNZZZNPNPNNZZCZCCNCNNCZNZZZCNPNPNNZNNNCNZCCPCZCZCZNPPZNNCPNZZNNNCPZZCPNPNZCNZZZZNPNPP
NNCPZPNZCZZPZPNZCPZZZPZNPPNNNCZNZNNCCCZZZPCPCZPPPCCCCZNPNCCPNCZPPPNPPCPPZNCZCZZZCPNCCZCPZPNCZ...

output:

2
2
2
2
2
3
2
3
2
2
2
2
3
2
3
3
3
2
2
2
2
2
2
2
2
3
2
2
2
2
2
3
2
3
3
2
3
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
3
2
2
3
2
3
2
3
2
2
3
2
3
1
2
2
2
3
2
2
2
2
2
3
2
2
2
2
3
3
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
3

result:

ok 100 lines

Test #38:

score: 0
Accepted
time: 2ms
memory: 4320kb

input:

40 100
NZZCNPPPCNCNPCZCZCPCNZPNCCNCCZNZNPNPZNPPZZNCNCPCZCZZPZPCNZPPCCZCZZCCCCNPZZPZNNNPCNZPPPNZPZPPCCNNZPP
CNPCNZZN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