답안 #1100783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100783 2024-10-14T17:18:55 Z Kirill22 Maxcomp (info1cup18_maxcomp) C++17
15 / 100
1 ms 516 KB
#include "bits/stdc++.h"

using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int> (m)), dp(n, vector<int> (m));
    set<array<int, 3>> tmp;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            dp[i][j] = a[i][j] - 1;
            tmp.insert({dp[i][j], i, j});
        }
    }
    while (!tmp.empty()) {
        auto [value, x, y] = *tmp.rbegin();
        tmp.erase(--tmp.end());
        for (auto [x2, y2] : vector<pair<int, int>> {{x - 1, y}, {x + 1, y}, {x, y - 1}, {x, y + 1}}) {
            if (x2 >= 0 && y2 >= 0 && x2 < n && y2 < m && dp[x2][y2] < value - 1) {
                tmp.erase({dp[x2][y2], x2, y2});
                dp[x2][y2] = value - 1;
                tmp.insert({dp[x2][y2], x2, y2});
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ans = max(ans, dp[i][j] - a[i][j]);
        }
    }
    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 516 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 516 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 516 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -