# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
65667 | imeimi2000 | 물탱크 (KOI18_watertank) | C++17 | 477 ms | 157428 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
int n, m, h;
int hp[1001][1001];
int vp[1001][1001];
int dist[1001][1001];
vector<pii> hs[1001];
int main() {
scanf("%d%d%d", &n, &m, &h);
for (int i = 0; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
scanf("%d", hp[i] + j);
if (hp[i][j] == -1) hp[i][j] = h;
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= m; ++j) {
scanf("%d", vp[i] + j);
if (vp[i][j] == -1) vp[i][j] = h;
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
dist[i][j] = h;
}
}
for (int i = 1; i <= n; ++i) {
dist[i][1] = min(dist[i][1], vp[i][0]);
dist[i][m] = min(dist[i][m], vp[i][m]);
}
for (int i = 1; i <= m; ++i) {
dist[1][i] = min(dist[1][i], hp[0][i]);
dist[n][i] = min(dist[n][i], hp[n][i]);
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
hs[dist[i][j]].emplace_back(i, j);
}
}
for (int it = 0; it < h; ++it) {
vector<pii> &st = hs[it];
while (!st.empty()) {
int x, y;
tie(x, y) = st.back();
st.pop_back();
if (dist[x][y] != it) continue;
int d;
d = max(dist[x][y], hp[x - 1][y]);
if (d < dist[x - 1][y]) {
hs[dist[x - 1][y] = d].emplace_back(x - 1, y);
}
d = max(dist[x][y], hp[x][y]);
if (d < dist[x + 1][y]) {
hs[dist[x + 1][y] = d].emplace_back(x + 1, y);
}
d = max(dist[x][y], vp[x][y - 1]);
if (d < dist[x][y - 1]) {
hs[dist[x][y - 1] = d].emplace_back(x, y - 1);
}
d = max(dist[x][y], vp[x][y]);
if (d < dist[x][y + 1]) {
hs[dist[x][y + 1] = d].emplace_back(x, y + 1);
}
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
ans += dist[i][j];
}
}
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |