40pts求调 WA
查看原帖
40pts求调 WA
1074696
tmlrock楼主2024/4/19 18:13
#include<bits/stdc++.h>
using namespace std;
using i16 = short;
using i32 = int;
using i64 = long long;
using u16 = unsigned short;
using u32 = unsigned;
using u64 = unsigned long long;
using f128 = long double;
using f64 = double;
using f32 = float;
//struct node ;
//using np = node*;
struct node {
	int idx, idy;
	inline node &set_node(int a, int b) {
		idx = a;
		idy = b;
		return *this;
	}
	inline int id() {
		return (idx << 7) | idy;
	}
};
inline node &make_node(int a, int b) {
	node tmp;
	return tmp.set_node(a, b);
}
inline bool operator < ( node x, node y) {
	return x.id() < y.id();
}
int ans = 0;
set<node> st;
int n, m;
int a[101][101];
#define dfv(x,y) {\
		if(a[idx][idy] > a[x][y] && (st.find(make_node(x,y)) == st.end()))\
			dfs(x,y,cnt+1);\
	}
inline void dfs(int idx, int idy, int cnt = 0) {
//	for (int i = 0; i < cnt; ++i)cout << "  ";
//	cout << idx << ' ' << idy << '\n';
	if (idx < 0 || idx >= n)return;
	if (idy < 0 || idy >= m)return;
	ans = max(ans, cnt);
	st.insert(make_node(idx, idy));
	dfv(idx - 1, idy);
	dfv(idx, idy + 1);
	dfv(idx + 1, idy);
	dfv(idx, idy - 1);
}
int main() {
	ios::sync_with_stdio(false), cin.tie(nullptr);
	st.clear();
	cin >> n >> m;
	for (int i = 0; i < n; ++i)for (int j = 0; j < m; ++j)cin >> a[i][j];
//	for (int i = 0; i < n; ++i)for (int j = 0; j < m; ++j)dfs(i, j);
	dfs(2, 2);
	cout << ans + 1;
	return 0;
}
2024/4/19 18:13
加载中...