UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212771#3828. Bxxttcc0675ms18588kbC++1.3kb2024-10-20 10:50:222024-10-20 14:37:56

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1010;
const int maxN = 1e6 + 10;
const int d[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
int t,m,n,a[N][N];
int b[maxN],ww[maxN],cnt = -1;
void dfs(int x,int y,int w,int len) {
	int sum = 0;
	for(int i = 0; i < 4; i++) {
		int sx = x + d[i][0],sy = y + d[i][1];
		if(sx >= 1 && sx <= n && sy >= 1 && sy <= m && a[sx][sy] > w) {
			len += 1;
			b[len] = a[sx][sy];
			dfs(sx,sy,a[sx][sy],len);
			len -= 1;
		} else {
			sum += 1;
		}
	}
	if(sum == 4) {
		if(len > cnt) {
			cnt = len;
			for(int i = 1;i <= cnt;++i){
				ww[i] = b[i];
			}
		} else if(len == cnt) {
			bool flag = false;
			for(int i = 1; i <= len; ++i) {
				if(b[i] < ww[i]) flag = true;
			}
			if(flag == true) {
				for(int i = 1; i <= len; ++i) {
					ww[i] = b[i];
				}
			}
		}
	}
	return;
}
int32_t main() {
	scanf("%lld",&t);
	while(t--) {
		cnt = 0;
		memset(b,0,sizeof(b));
		memset(ww,0,sizeof(ww));
		scanf("%lld %lld",&n,&m);
		for(int i = 1; i <= n; ++i) {
			for(int j = 1; j <= m; ++j) {
				scanf("%lld",&a[i]);
			}
		}
		for(int i = 1; i <= n;++i) {
			for(int j = 1; j <= m; ++j) {
				b[1] = a[i][j];
				dfs(i,j,a[i][j],1);
			}
		}
		printf("%lld\n",cnt);
		for(int i = 1;i <= cnt;++i){
			printf("%lld ",ww[i]);
		}
		printf("\n");
	}
	return 0;
}

详细

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

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 9ms
memory: 16836kb

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:

1
0 
1
0 
1
0 
1
0 
1
0 
1
0 
1
0 
1
0 
1
0 
1
0 

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 14ms
memory: 16948kb

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:

1
0 
1
0 
1
0 
1
0 
1
0 
1
0 
1
0 
1
0 
1
0 
1
0 

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 215ms
memory: 16832kb

input:

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

output:

2
0 172089 
2
0 172089 
2
0 16956 
2
0 159781 
2
0 159781 
2
0 100000 
2
0 100000 
2
0 100000 
2
0 1...

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 213ms
memory: 16840kb

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:

1
0 
3
0 82536 93682 
2
0 82536 
4
0 150509 159975 167050 
4
0 51671 60152 167050 
2
0 51671 
3
0 66...

result:

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

Subtask #5:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 224ms
memory: 18588kb

input:

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

output:

7
0 19315 20286 65055 100671 150094 177396 
6
0 397 21884 41773 137159 193885 
7
0 21303 90771 10497...

result:

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