Submission #81637

#TimeUsernameProblemLanguageResultExecution timeMemory
81637tjdgus4384물탱크 (KOI18_watertank)C++14
100 / 100
1053 ms92620 KiB
#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)

watertank.cpp: In function 'int main()':
watertank.cpp:55:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0;i < v[s].size();i++)
                       ~~^~~~~~~~~~~~~
watertank.cpp:20: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:33:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
watertank.cpp:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
#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...