UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212739#3828. BFisher201300ms1268kbC++111.1kb2024-10-20 10:21:472024-10-20 14:36:58

answer

#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> v;
vector<int> tmp;
string ans = "";
int mx = 0, dir[][2] = {0, 1, 0, -1, 1, 0, -1, 0}, n, m;
void DFS (int r, int c, string a) {
	if (a.size() > mx || a.size() == mx && a < ans) {
		ans = a;
		mx = ans.size();
	}
	int u = int(a.back() - '0');
	for (int i = 0; i < 4; i++) {
		int dr = r + dir[i][0], dc = c + dir[i][1];
		if (1 <= dr && dr <= n && 1 <= dc && dc <= m && v[dr][dc] > u) {
			a.push_back(v[dr][dc] + '0');
			DFS(dr, dc, a);
			a.pop_back();
		}
	}
}
int main() {
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		tmp.push_back(0);
		v.push_back(tmp);
		tmp.clear();
		for (int i = 1; i <= n; i++) {
			tmp.push_back(0);
			for (int j = 1; j <= m; j++) {
				int num;
				cin >> num;
				tmp.push_back(num);
			}
			v.push_back(tmp);
			tmp.clear();
		}
		string a;
		a.push_back(v[1][1] + '0');
		DFS(1, 1, a);
		cout << mx << endl;
		for(int i = 0; i < ans.size(); i++){
			cout << ans[i] - '0' << " ";
		}
		cout << endl;
		v.clear();
		ans = "", mx = 0;
	}
	return 0;
}

Details

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

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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: 1268kb

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
1 5 
3
2 5 8 
9
0 1 2 3 4 5 6 7 8 
3
3 4 7 
1
5 
3
5 6 7 
2
2 8 
10
0 1 2 3 4 5 6 7 8 9 
1
3 
9
0 ...

result:

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

Subtask #2:

score: 0
Memory Limit Exceeded

Test #3:

score: 0
Memory Limit Exceeded

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:


result:


Subtask #3:

score: 0
Memory Limit Exceeded

Test #5:

score: 0
Memory Limit Exceeded

input:

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

output:


result:


Subtask #4:

score: 0
Memory Limit Exceeded

Test #6:

score: 0
Memory Limit Exceeded

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:


result:


Subtask #5:

score: 0
Memory Limit Exceeded

Test #7:

score: 0
Memory Limit Exceeded

input:

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

output:


result: