QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#863673#8114. LabirintUnforgettablepl70 ✓7ms6412kbC++201.4kb2025-01-19 21:06:502025-01-19 21:06:53

Judging History

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

  • [2025-01-19 21:06:53]
  • 评测
  • 测评结果:70
  • 用时:7ms
  • 内存:6412kb
  • [2025-01-19 21:06:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long


map<char,int> lookup = {{'P',0},{'C',1},{'Z',2},{'N',3}};

int32_t main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	vector rightDoor(n+1,vector<int>(m+1,4));
	vector downDoor(n+1,vector<int>(m+1,4));
	for(int i=1;i<=n;i++){
		for(int j=1;j<m;j++){
			char x;cin>>x;
			rightDoor[i][j]=lookup[x];
		}
	}
	for(int i=1;i<n;i++){
		for(int j=1;j<=m;j++){
			char x;cin>>x;
			downDoor[i][j]=lookup[x];
		}
	}
	vector component(16,vector(n+1,vector(m+1,-1)));
	function<void(int,int,int,int)> dfs = [&](int x,int y,int kind,int compo){
		if(component[kind][x][y]!=-1)return;
		component[kind][x][y]=compo;
		if(kind&(1<<rightDoor[x][y]))dfs(x,y+1,kind,compo);
		if(kind&(1<<rightDoor[x][y-1]))dfs(x,y-1,kind,compo);
		if(kind&(1<<downDoor[x][y]))dfs(x+1,y,kind,compo);
		if(kind&(1<<downDoor[x-1][y]))dfs(x-1,y,kind,compo);
	};
	for(int kind = 0;kind<16;kind++){
		int components = 0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(component[kind][i][j]!=-1)continue;
				dfs(i,j,kind,++components);
			}
		}
	}
	int q;
	cin >> q;
	for(int i=1;i<=q;i++){
		int a,b,c,d;cin>>a>>b>>c>>d;
		int ans = 5;
		for(int kind=0;kind<16;kind++){
			if(component[kind][a][b]==component[kind][c][d])ans=min(ans,(int)__builtin_popcount(kind));
		}
		cout << ans << '\n';
	}
}

详细

Subtask #1:

score: 11
Accepted

Test #1:

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

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: 11
Accepted
time: 1ms
memory: 3840kb

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: 11
Accepted
time: 0ms
memory: 3840kb

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: 11
Accepted
time: 0ms
memory: 3840kb

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: 11
Accepted
time: 0ms
memory: 3840kb

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: 11
Accepted
time: 0ms
memory: 3840kb

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: 5ms
memory: 6272kb

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: 13
Accepted
time: 4ms
memory: 6400kb

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: 13
Accepted
time: 4ms
memory: 6400kb

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: 13
Accepted
time: 4ms
memory: 6400kb

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2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PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

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

result:

ok 100 lines

Test #13:

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

input:

100 2
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
C...

output:

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

result:

ok 100 lines

Test #14:

score: 13
Accepted
time: 1ms
memory: 3968kb

input:

10 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

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

result:

ok 100 lines

Test #15:

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

input:

100 10
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPPPPPPPP
PPP...

output:

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

result:

ok 100 lines

Subtask #3:

score: 24
Accepted

Test #16:

score: 24
Accepted
time: 6ms
memory: 6400kb

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: 24
Accepted
time: 6ms
memory: 6400kb

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: 24
Accepted
time: 5ms
memory: 6400kb

input:

100 100
PPPPPPCPCCPPCCCPPCCCPCPPCC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100 lines

Test #20:

score: 24
Accepted
time: 5ms
memory: 6400kb

input:

100 100
CCCCPPCPPPPPCCCCPCCCPCPPCPCPPPCPCPCCCCCCPPCPCPPCPPCCCPPPPCCCCPCPPPCCCCPPPPCPPPCCPCPPPCCPPPPPPPPCPCP
CPPPCPPCCCPPPPPCCPCCCCCCCPCCPPPCCCCPPCPPCCCPPCPCCCPPCPPCCPCCCCCPPCCCPCPPCPCPCCPPCCCPCCCPCCPPCCCPPPP
CCPCPCCCCPPPCPPPCPCCPPCPCPPCCCPPPPCCCCPPCCPCPPPPPCCCPCCCCPPPPPCCPCPPCPPCPPCCPCCCCCPCCPPPCCPP...

output:

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

result:

ok 100 lines

Test #21:

score: 24
Accepted
time: 4ms
memory: 6400kb

input:

100 100
PCCCPCPCPCPCCPPPPCCPPCPPPPPCPPCPPPPPCCCCCPPPPCCCCPCCCPCCPCPPCCCPPPPCPCCCPCCCCPCCCPCCCPCPPCPCCPPCPPP
PPCPCPCCCCCPPCCCPCPPPCPPCPCCCPCCPCPPCCPPCPCCCCCPCCPCPPCCCCPPCCCPPCPCCCCCPPPCPCCCCPPCCCCPCPPCPPCPCCP
PCPCCCCCPCCPCCCCPPPCPCCPCCCCCPPCPCPPPPPPPPCPCPPCCPCCCPPPCPPCCCPCPPCPCPPPPCPPCPPPPCPPPCCCPCCC...

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: 24
Accepted
time: 0ms
memory: 3840kb

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: 24
Accepted
time: 1ms
memory: 3968kb

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: 24
Accepted
time: 0ms
memory: 4096kb

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: 4ms
memory: 6400kb

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: 22
Accepted
time: 7ms
memory: 6400kb

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: 22
Accepted
time: 6ms
memory: 6400kb

input:

100 100
PCCCPNPZCCNNCPPNNCCNPPNCCZPNZCPZCZNZCNNZNZZZZZPCZCNPZNPPPZPZNZZCNZZPNZZZNCCCNPCPPZPCZCNPNCNZPNZZZCZ
PCPCPCNCZZZCPCNNCZNZPZZCNPPCZNCPZCPZPZCCZZCPZZCNPPCPCCCPZZNCCPPNPPZZPCCNPPZNNNNZCCPCPZPPZCNZZNNPNCP
NPZCZZNPZNPCNZNPNPCCCPCCZPCZCNNZNCPCCCZPCNZCPCPPPNCCNCNPPPPPCPZCNCCCNNCZCNPCZNZCNZNCCCZNZZPP...

output:

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

result:

ok 100 lines

Test #28:

score: 22
Accepted
time: 7ms
memory: 6272kb

input:

100 100
ZPPCZNZNNNZZZZPPPCCCNCPNCCNCNCNZZZZZNPPPZPPPPZPNCPZCNNCNCCNZCCPCNNNPZZNNPZZNPCCNCNCNNZCZCZZPCNPNZNP
PNPCNZZZZCPPNCNCZPCCZZNZZPZNCCNZNNPPCCCCCNCCNCNNZCNCCPPPNPCNCPZNNNPZPPCPCCNNPNNPNZZZNCPZZPNCZCPCZCP
ZPZPPPZZPZNCPCNCZNNNCZZNCPCZCNNZPZZNPPNPZNNNCZCNPPCNPNCPPCPNNZNZCCZPCZNZPCPPNPNNCPNZCPNZCCNZ...

output:

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

result:

ok 100 lines

Test #29:

score: 22
Accepted
time: 6ms
memory: 6400kb

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: 22
Accepted
time: 6ms
memory: 6400kb

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: 22
Accepted
time: 6ms
memory: 6412kb

input:

100 100
CCCCPPCPNCCZCZNPPPNCZPNNCPZPNCCPPZCPNPZPCNPPCPPZNNPC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
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: 22
Accepted
time: 1ms
memory: 4096kb

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: 22
Accepted
time: 2ms
memory: 4352kb

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: 22
Accepted
time: 0ms
memory: 4736kb

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: 22
Accepted
time: 3ms
memory: 4992kb

input:

40 100
NZZCNPPPCNCNPCZCZCPCNZPNCCNCCZNZNPNPZNPPZZNCNCPCZCZZPZPCNZPPCCZCZZCCCCNPZZPZNNNPCNZPPPNZPZPPCCNNZPP
CNPCNZZNCNZPPPPCPZPNPNCNZPNZNPZCNNNZNCZNNCNPZPNZPNCCCCNNPPCPCCNCCCPZPPZNPPZPCZZNNCCZNCPPPPPCCPZZCCN
ZZPZNZCCPCNPPNPZNNCPZZNNCZNPPCPZPPNNPPNNPNNZCNZPCPPNCZCNZPCNCPCCNZNNZPZPCPCZNZCNNNCCNZCPPNCZC...

output:

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