Submission #65667

#TimeUsernameProblemLanguageResultExecution timeMemory
65667imeimi2000물탱크 (KOI18_watertank)C++17
100 / 100
477 ms157428 KiB
#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)

watertank.cpp: In function 'int main()':
watertank.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &n, &m, &h);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
watertank.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", hp[i] + j);
             ~~~~~^~~~~~~~~~~~~~~~~
watertank.cpp:37:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", vp[i] + j);
             ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...