UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212764#3828. Bhuangyuhang01229ms19156kbC++111.6kb2024-10-20 10:43:452024-10-20 14:37:29

answer

#include<bits/stdc++.h>
using namespace std;
int a[200000+5];
int T,n,m;
int get_num(int x,int y)
{
	return (x-1)*m+y;	
}
int hu[200000+5];//1:down 2:up 3:right 4:left
int dp[200000+5];
int dir[4][2]={0,1,0,-1,1,0,-1,0};//
int fun(int x,int y)
{
	if(dp[get_num(x,y)])
		return dp[get_num(x,y)];
	int l[4]={0};
	for(int i=0;i<4;i++)
	{
		if(x+dir[i][0]>0&&x+dir[i][0]<=n&&y+dir[i][1]>0&&y+dir[i][1]<=m&&a[get_num(x,y)]<a[get_num(x+dir[i][0],y+dir[i][1])])
		{
			l[i]=fun(x+dir[i][0],y+dir[i][1]);
		}
	}
	int maxx=max({l[0],l[1],l[2],l[3]});
	if(maxx==0)
	{
		hu[get_num(x,y)]=0; 
		return dp[get_num(x,y)]=1;	
	}
	int cj1=INT_MAX,cj2;
	for(int i=0;i<=3;i++)
	{
		if(l[i]==maxx)
		{
			if(a[get_num(x+dir[i][0],y+dir[i][1])]<cj1)
			{
				cj1=a[get_num(x+dir[i][0],y+dir[i][1])];
				cj2=i+1;
			}
		}
	}
	hu[get_num(x,y)]=cj2;	 
	return dp[get_num(x,y)]=maxx+1;
}
void DFS(int x,int y)
{
	printf("%d ",a[get_num(x,y)]);
	if(hu[get_num(x,y)]==0)
		printf("\n");
	else
		DFS(x+dir[hu[get_num(x,y)]-1][0],y+dir[hu[get_num(x,y)]-1][1]);
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		memset(dp,0,sizeof(dp));
		memset(hu,0,sizeof(hu));
		scanf("%d %d",&n,&m);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				scanf("%d",&a[get_num(i,j)]);
		int maxx=0,fx,fy,c=INT_MAX;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
			{
				if(fun(i,j)>=maxx)
				{
					maxx=fun(i,j);
					if(a[get_num(i,j)]<c)
					{
						fx=i,fy=j,c=a[get_num(i,j)];
					}
				}
			}
		printf("%d\n",maxx);
		DFS(fx,fy);
	}
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 1ms
memory: 2748kb

input:

10
3 3
0 1 2
3 4 5
6 7 8
3 3
0 1 2
3 4 5
6 8 7
3 3
0 1 2
3 4 5
7 6 8
3 3
0 1 2
3 4 5
7 8 6
3 3
0 1 2...

output:

5
0 1 2 5 8 
6
0 1 2 5 7 8 
5
0 1 2 5 8 
6
0 1 2 5 6 8 
5
0 1 2 5 7 
7
0 1 2 5 6 7 8 
5
0 1 2 6 8 
6...

result:

ok 64 numbers

Test #2:

score: -20
Wrong Answer
time: 2ms
memory: 2748kb

input:

10
1 10
1 5 0 8 2 9 6 3 4 7
1 10
2 5 8 0 9 7 3 1 6 4
3 3
0 1 2
5 4 3
6 7 8
1 10
3 4 7 2 5 6 9 0 1 8
...

output:

3
0 5 
4
1 3 7 9 
9
0 1 2 3 4 5 6 7 8 
4
2 5 6 9 
3
1 7 9 
4
2 3 7 
3
0 4 7 
10
0 1 2 3 4 5 6 7 8 9 ...

result:

wrong answer 2nd numbers differ - expected: '3', found: '0'

Subtask #2:

score: 0
Wrong Answer

Test #3:

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

input:

10
22 45
0 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...

output:

990
0 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 3...

result:

wrong answer 993rd numbers differ - expected: '68', found: '16'

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 439ms
memory: 19156kb

input:

10
2 100000
143604 106821 145034 44402 118718 156663 77133 28800 81890 12336 191537 118894 103331 75...

output:

13
3208 11640 16048 97925 103377 133243 164055 169735 170878 
9
6387 23313 56902 91230 103279 128798...

result:

wrong answer 2nd numbers differ - expected: '11306', found: '3208'

Subtask #4:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 458ms
memory: 19156kb

input:

10
1 200000
0 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...

output:

200000
0 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 3...

result:

wrong answer 200003rd numbers differ - expected: '1378', found: '81'

Subtask #5:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 328ms
memory: 19152kb

input:

10
145 1379
140324 86968 96426 123781 39754 103720 60835 118904 114639 53717 27146 110309 39232 5608...

output:

14
744 15056 117002 121319 127474 134877 168055 176627 188415 
14
7010 21330 27021 28270 84470 97602...

result:

wrong answer 2nd numbers differ - expected: '8850', found: '744'