-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.c
107 lines (107 loc) · 2.62 KB
/
B.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include<stdio.h>
int main()
{
long long int t,n,m,i,j,ara[301][301],p;
scanf("%lld",&t);
while(t--)
{
p=0;
scanf("%lld%lld",&n,&m);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
scanf("%lld",&ara[i][j]);
}
if(ara[0][0]>2 || ara[0][m-1]>2 || ara[n-1][0]>2 || ara[n-1][m-1]>2)
{
printf("NO\n");
continue;
}
else
{
for(i=0;i<n;i++)
{
if(i==0 || i==n-1)
{
for(j=1;j<m-1;j++)
{
if(ara[i][j]>3)
{
p=1;
break;
}
}
if(p==1)
break;
}
else
{
if(ara[i][0]>3 || ara[i][m-1]>3)
{
p=1;
break;
}
}
}
if(p==1)
{
printf("NO\n");
continue;
}
else
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(ara[i][j]>4)
{
p=2;
break;
}
}
if(p==2)
break;
}
}
if(p==2)
{
printf("NO\n");
continue;
}
else
{
printf("YES\n");
for(i=1;i<n-1;i++)
{
for(j=1;j<m-1;j++)
ara[i][j]=4;
}
for(i=0;i<n;i++)
{
if(i==0 || i==n-1)
{
for(j=1;j<m-1;j++)
ara[i][j]=3;
}
else
{
ara[i][0]=3;
ara[i][m-1]=3;
}
}
ara[0][0]=2;
ara[0][m-1]=2;
ara[n-1][0]=2;
ara[n-1][m-1]=2;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
printf("%lld ",ara[i][j]);
printf("\n");
}
}
}
}
return 0;
}