Submission #69146

#TimeUsernameProblemLanguageResultExecution timeMemory
69146red1108물탱크 (KOI18_watertank)C++17
100 / 100
1240 ms207564 KiB
#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)

watertank.cpp: In function 'int main()':
watertank.cpp:11: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:17:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &ina);
             ~~~~~^~~~~~~~~~~~
watertank.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &ina);
             ~~~~~^~~~~~~~~~~~
#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...