#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 int main(){ int H,W,N; cin>>H>>W>>N; vector A(H,vector(W)); rep(i,H){ rep(j,W){ scanf("%d",&A[i][j]); } } vector dx = {0,0,1,-1},dy = {1,-1,0,0}; scc_graph S(H*W); rep(i,H){ rep(j,W){ rep(k,4){ int ii = i+dx[k],jj = j+dy[k]; if(ii<0||ii>=H||jj<0||jj>=W)continue; if(A[i][j] <= A[ii][jj]){ S.add_edge(i*W+j,ii*W+jj); } } } } auto s = S.scc(); vector> pos(H,vector(W)); rep(i,s.size()){ rep(j,s[i].size()){ pos[s[i][j]/W][s[i][j]%W] = i; } } vector dp(s.size(),1); rep(i,s.size()){ rep(j,s[i].size()){ int y = s[i][j]/W,x = s[i][j]%W; rep(k,4){ int yy = y+dx[k],xx = x+dy[k]; if(yy<0||yy>=H||xx<0||xx>=W)continue; if(pos[yy][xx]<=pos[y][x])continue; dp[pos[yy][xx]] = max(dp[pos[yy][xx]],dp[pos[y][x]]+1); } } } int ans = 0; rep(i,dp.size()){ // cout<