# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
69146 | red1108 | 물탱크 (KOI18_watertank) | C++17 | 1240 ms | 207564 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 <bits/stdc++.h>
using namespace std;
int dis[1000010];
vector<pair<int,int> > graph[1000010];
priority_queue<pair<int,int> > pq;
int n, m, h;
bool visit[1000100];
int main()
{
int i, j, ina, st,from,to;
scanf("%d %d %d", &n,&m,&h);
st=n*m+1;
for(i=1;i<=n+1;i++)
{
for(j=1;j<=m;j++)
{
scanf("%d", &ina);
if(ina==-1) ina=h;
from=(i-2)*m+j;
to=(i-1)*m+j;
if(from<1||from>n*m) from=st;
if(to<1||to>n*m) to=st;
graph[from].push_back({ina,to});
graph[to].push_back({ina,from});
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m+1;j++)
{
scanf("%d", &ina);
if(ina==-1) ina=h;
from=(i-1)*m+j-1;
to=(i-1)*m+j;
if(j==1) from=st;
if(j==m+1) to=st;
graph[from].push_back({ina,to});
graph[to].push_back({ina,from});
}
}
visit[st]=1;
pq.push({0,st});
while(!pq.empty())
{
int cur=pq.top().second;
if((-1)*pq.top().first>dis[cur]){pq.pop();continue;}
pq.pop();
for(auto i:graph[cur])
{
if(!visit[i.second]||dis[i.second]>max(dis[cur],i.first))
{
dis[i.second]=max(dis[cur],i.first);
visit[i.second]=1;
pq.push({-dis[i.second],i.second});
}
}
}
long long ans=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
ans=ans+dis[(i-1)*m+j];
}
}
printf("%lld", ans);
}
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... |