답안 #496882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496882 2021-12-22T06:03:36 Z Nalrimet Maxcomp (info1cup18_maxcomp) C++17
0 / 100
500 ms 524292 KB
#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;

const int N = 1e3 + 5;
const int inf = 1e9+7;

int n, m, dist, a[N][N], cur, mx, ans;
bool used[N][N];

void rec(int i, int j, int mn){
    dist++;
    if(cur <= dist) {dist--; return;}
    if(cur >= mn + dist){
        cur = mn + dist;
    }
    if(a[i][j + 1] <= mx && !used[i][j + 1]){
        rec(i, j + 1, min(mn, a[i][j + 1]));
    }
    if(a[i][j - 1] <= mx && !used[i][j - 1]){
        rec(i, j - 1, min(mn, a[i][j - 1]));
    }
    if(a[i + 1][j] <= mx && !used[i + 1][j]){
        rec(i + 1, j, min(mn, a[i + 1][j]));
    }
    if(a[i - 1][j] <= mx && !used[i - 1][j]){
        rec(i - 1, j, min(mn, a[i - 1][j]));
    }
    dist--;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	cin >> n >> m;

	for(int i = 1; i <= n; ++i){
        a[i][0] = inf;
        a[i][m + 1] = inf;
        for(int j = 1; j <= m; ++j){
            cin >> a[i][j];
        }
	}

	for(int j = 1; j <= m; ++j){
        a[0][j] = inf;
        a[n + 1][j] = inf;
	}

	for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= m; ++j){
            memset(used, 0, sizeof(used));
            mx = a[i][j];
            cur = inf;
            rec(i, j, a[i][j]);
//            cout << cur << ' ' << a[i][j] << '\n';
            ans = max(a[i][j] - cur, ans);
        }
	}

	cout << ans;

	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Runtime error 311 ms 524292 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1082 ms 2508 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Runtime error 311 ms 524292 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Runtime error 311 ms 524292 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -