# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81637 | tjdgus4384 | 물탱크 (KOI18_watertank) | C++14 | 1053 ms | 92620 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<cstdio>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int, int> p;
int n, m, h;
int idx[1050][1050];
vector<p> v[1000500];
int ans[1000500];
void make(int a, int b, int x)
{
v[a].push_back({b, x});
v[b].push_back({a, x});
}
int main()
{
int x;
scanf("%d %d %d", &n, &m, &h);
int cnt = 0;
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= m;j++)
{
idx[i][j] = ++cnt;
}
}
for(int i = 1;i <= n + 1;i++)
{
for(int j = 1;j <= m;j++)
{
scanf("%d", &x);
if(x != -1) make(idx[i][j], idx[i - 1][j], x);
}
}
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= m + 1;j++)
{
scanf("%d", &x);
if(x != -1) make(idx[i][j], idx[i][j - 1], x);
}
}
for(int i = 0;i <= n*m;i++) ans[i] = h;
ans[0] = 0;
priority_queue<p, vector<p>, greater<p> > pq;
pq.push({0, 0});
while(!pq.empty())
{
int f = pq.top().first;
int s = pq.top().second;
pq.pop();
if(f != ans[s]) continue;
for(int i = 0;i < v[s].size();i++)
{
int next = v[s][i].first;
int d = v[s][i].second;
int nexth = max(f, d);
if(ans[next] > nexth)
{
ans[next] = nexth;
pq.push({nexth, next});
}
}
}
int res = 0;
for(int i = 1;i <= n*m;i++) res += ans[i];
printf("%d", res);
}
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... |