UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212666#3828. Bwushuyu02203ms8588kbC++11795b2024-10-20 09:11:032024-10-20 14:35:39

answer

#include<bits/stdc++.h>
using namespace std;
long long t,n,m,mi=INT_MAX,x,y;
long long a[10000][10000],ans[100000],cnt,d[10][2]={{-1,0},{1,0},{0,-1},{0,1}};
int main()
{
	cin>>t;
	while(t--)
	{
		cnt=0;
		cin>>n>>m;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				cin>>a[i][j]; 
				if(a[i][j]<mi)
				{
					x=i,y=j,mi=a[i][j];
				}
			}
		}
		while(1)
		{
			ans[++cnt]=mi;
			mi=INT_MAX;
			long long e,r;
			for(int i=0;i<4;i++)
			{
				long long q=x,w=y;
				q+=d[i][0];
				w+=d[i][1];
				if(q>=1&&q<=n&&w>=1&&w<=m&&mi>a[q][w]&&a[q][w]>a[x][y])
					mi=a[q][w],e=q,r=w;
			}
			if(mi==INT_MAX)
				break;
			x=e,y=r;
		}
		cout<<cnt<<"\n";
		for(int i=1;i<=cnt;i++)
		{
			cout<<ans[i]<<" ";
		}
		cout<<"\n";
	}
	return 0;
}

详细

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

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 0ms
memory: 1212kb

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: 0ms
memory: 1212kb

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:

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

result:

wrong answer 1st numbers differ - expected: '3', found: '2'

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 1344kb

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 992nd numbers differ - expected: '9', found: '6'

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 627ms
memory: 3616kb

input:

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

output:

1
0 
3
0 52559 71075 
3
0 120695 156678 
2
0 175423 
3
0 34497 47197 
20000
0 1 2 3 4 5 6 7 8 9 10 1...

result:

wrong answer 1st numbers differ - expected: '13', found: '1'

Subtask #4:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 929ms
memory: 3616kb

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 200002nd numbers differ - expected: '12', found: '3'

Subtask #5:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 647ms
memory: 8588kb

input:

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

output:

6
0 36399 40625 84019 90544 113072 
4
0 32415 107338 142810 
4
0 45890 58142 96361 
6
0 18648 55432 ...

result:

wrong answer 1st numbers differ - expected: '14', found: '6'