#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); /* f(X)=Xより小さい数を通る回数がK回以下か? これのleft maxが答え。 */ int N, M, K; cin >> N >> M >> K; vector a(N, vector(M)); for (int i=0; i> a[i][j]; } } auto f=[&](int i, int j){ return 0 <= i && i < N && 0 <= j && j < M; }; int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; const int inf=1e9; auto bfs=[&](ll X){ int x, y, nx, ny, c, alt; deque> que; vector dist(N, vector(M, inf)); dist[0][0] = (a[0][0] < X); que.push_back({0, 0}); while(!que.empty()){ tie(x, y) = que.front(); que.pop_front(); for (int i=0; i<4; i++){ nx = x+dx[i]; ny = y+dy[i]; if (f(nx, ny)){ c = (a[nx][ny]1){ c = (l+r)/2; if (bfs(c)) l=c; else r=c; } cout << l << endl; return 0; }