-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAMR11A_re_ac.cpp
More file actions
53 lines (52 loc) · 984 Bytes
/
AMR11A_re_ac.cpp
File metadata and controls
53 lines (52 loc) · 984 Bytes
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
#include<stdio.h>
int s[10000][505];
int main()
{
int t,r,c,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&r,&c);
for(i=0;i<r;i++)
{
s[i][0]=0;
}
for(j=0;j<c;j++)
{
s[0][j]=0;
}
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
scanf("%d",&s[i][j]);
s[r][c]=1;
for(i=r-1;i>0;i--)
{
s[i][c]=s[i+1][c]-s[i][c];
if(s[i][c]<1)
s[i][c]=1;
}
for(j=c-1;j>0;j--)
{
s[r][j]=s[r][j+1]-s[r][j];
if(s[r][j]<1)
s[r][j]=1;
}
for(i=r-1;i>0;i--)
for(j=c-1;j>0;j--)
{
if(s[i+1][j]<s[i][j+1])
s[i][j]=s[i+1][j]-s[i][j];
else
s[i][j]=s[i][j+1]-s[i][j];
if(s[i][j]<1)
s[i][j]=1;
}
/*for(i=0;i<=r;i++)
{for(j=0;j<=c;j++)
printf("%d ",s[i][j]);
printf("\n");
}*/
printf("%d\n",s[1][1]);
}
return 0;
}