답안 #322257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
322257 2020-11-14T10:40:02 Z tjdgus4384 물탱크 (KOI18_watertank) C++14
100 / 100
971 ms 111248 KB
#include<bits/stdc++.h>
using namespace std;
int N, M, H, t, d[1010][1010], ans;
vector<pair<pair<int, int>, int> > v[1010][1010];
priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >, greater<pair<int, pair<int, int> > > > q;

int main(){
    scanf("%d %d %d", &N, &M, &H);
    for(int i = 0;i < N;i++){
        for(int j = 0;j < M;j++){
            d[i][j] = H;
        }
    }
    for(int i = 0;i < N+1;i++){
        for(int j = 0;j < M;j++){
            scanf("%d", &t);
            if(t == -1) continue;
            if(i == 0){
                if(t < d[0][j]){
                    q.push({t, {0, j}});
                    d[0][j] = t;
                }
            }
            else if(i == N){
                if(t < d[N-1][j]){
                    q.push({t, {N-1, j}});
                    d[N-1][j] = t;
                }
            }
            else{
                v[i-1][j].push_back({{i, j}, t});
                v[i][j].push_back({{i-1, j}, t});
            }
        }
    }
    for(int i = 0;i < N;i++){
        for(int j = 0;j < M+1;j++){
            scanf("%d", &t);
            if(t == -1) continue;
            if(j == 0){
                if(t < d[i][0]){
                    q.push({t, {i, 0}});
                    d[i][0] = t;
                }
            }
            else if(j == M){
                if(t < d[i][M-1]){
                    q.push({t, {i, M-1}});
                    d[i][M-1] = t;
                }
            }
            else{
                v[i][j-1].push_back({{i, j}, t});
                v[i][j].push_back({{i, j-1}, t});
            }
        }
    }

    while(!q.empty()){
        int q1 = q.top().first;
        int qx = q.top().second.first;
        int qy = q.top().second.second;
        q.pop();
        if(q1 > d[qx][qy]) continue;
        for(int i = 0;i < v[qx][qy].size();i++){
            int nx = v[qx][qy][i].first.first;
            int ny = v[qx][qy][i].first.second;
            if(d[nx][ny] > max(q1, v[qx][qy][i].second)){
                d[nx][ny] = max(q1, v[qx][qy][i].second);
                q.push({d[nx][ny], {nx, ny}});
            }
        }
    }

    for(int i = 0;i < N;i++){
        for(int j = 0;j < M;j++){
            ans += d[i][j];
        }
    }
    printf("%d", ans);
    return 0;
}

Compilation message

watertank.cpp: In function 'int main()':
watertank.cpp:65:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int i = 0;i < v[qx][qy].size();i++){
      |                       ~~^~~~~~~~~~~~~~~~~~
watertank.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |     scanf("%d %d %d", &N, &M, &H);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watertank.cpp:16:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |             scanf("%d", &t);
      |             ~~~~~^~~~~~~~~~
watertank.cpp:38:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |             scanf("%d", &t);
      |             ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 24300 KB Output is correct
2 Correct 19 ms 24300 KB Output is correct
3 Correct 15 ms 24300 KB Output is correct
4 Correct 16 ms 24300 KB Output is correct
5 Correct 15 ms 24300 KB Output is correct
6 Correct 15 ms 24300 KB Output is correct
7 Correct 15 ms 24300 KB Output is correct
8 Correct 15 ms 24300 KB Output is correct
9 Correct 16 ms 24300 KB Output is correct
10 Correct 15 ms 24428 KB Output is correct
11 Correct 15 ms 24300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 24300 KB Output is correct
2 Correct 15 ms 24300 KB Output is correct
3 Correct 15 ms 24300 KB Output is correct
4 Correct 16 ms 24428 KB Output is correct
5 Correct 16 ms 24300 KB Output is correct
6 Correct 15 ms 24300 KB Output is correct
7 Correct 16 ms 24300 KB Output is correct
8 Correct 15 ms 24300 KB Output is correct
9 Correct 15 ms 24300 KB Output is correct
10 Correct 15 ms 24300 KB Output is correct
11 Correct 16 ms 24300 KB Output is correct
12 Correct 15 ms 24300 KB Output is correct
13 Correct 16 ms 24300 KB Output is correct
14 Correct 16 ms 24300 KB Output is correct
15 Correct 16 ms 24300 KB Output is correct
16 Correct 15 ms 24300 KB Output is correct
17 Correct 16 ms 24300 KB Output is correct
18 Correct 15 ms 24300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 28396 KB Output is correct
2 Correct 15 ms 24300 KB Output is correct
3 Correct 208 ms 32108 KB Output is correct
4 Correct 268 ms 50028 KB Output is correct
5 Correct 15 ms 24300 KB Output is correct
6 Correct 474 ms 69484 KB Output is correct
7 Correct 217 ms 37484 KB Output is correct
8 Correct 553 ms 91124 KB Output is correct
9 Correct 215 ms 39296 KB Output is correct
10 Correct 15 ms 24300 KB Output is correct
11 Correct 543 ms 77804 KB Output is correct
12 Correct 16 ms 24300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 24684 KB Output is correct
2 Correct 14 ms 24300 KB Output is correct
3 Correct 16 ms 24300 KB Output is correct
4 Correct 15 ms 24300 KB Output is correct
5 Correct 15 ms 24300 KB Output is correct
6 Correct 15 ms 24300 KB Output is correct
7 Correct 16 ms 24556 KB Output is correct
8 Correct 17 ms 24556 KB Output is correct
9 Correct 15 ms 24300 KB Output is correct
10 Correct 16 ms 24428 KB Output is correct
11 Correct 16 ms 24556 KB Output is correct
12 Correct 15 ms 24300 KB Output is correct
13 Correct 17 ms 24556 KB Output is correct
14 Correct 16 ms 24300 KB Output is correct
15 Correct 15 ms 24300 KB Output is correct
16 Correct 18 ms 24684 KB Output is correct
17 Correct 16 ms 24428 KB Output is correct
18 Correct 17 ms 24684 KB Output is correct
19 Correct 15 ms 24300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 24684 KB Output is correct
2 Correct 15 ms 24300 KB Output is correct
3 Correct 15 ms 24300 KB Output is correct
4 Correct 15 ms 24300 KB Output is correct
5 Correct 16 ms 24300 KB Output is correct
6 Correct 222 ms 34156 KB Output is correct
7 Correct 15 ms 24300 KB Output is correct
8 Correct 16 ms 24300 KB Output is correct
9 Correct 194 ms 35180 KB Output is correct
10 Correct 17 ms 24428 KB Output is correct
11 Correct 15 ms 24300 KB Output is correct
12 Correct 207 ms 34172 KB Output is correct
13 Correct 198 ms 37100 KB Output is correct
14 Correct 15 ms 24300 KB Output is correct
15 Correct 305 ms 62444 KB Output is correct
16 Correct 16 ms 24300 KB Output is correct
17 Correct 15 ms 24300 KB Output is correct
18 Correct 15 ms 24300 KB Output is correct
19 Correct 275 ms 54892 KB Output is correct
20 Correct 17 ms 24556 KB Output is correct
21 Correct 971 ms 111248 KB Output is correct
22 Correct 17 ms 24556 KB Output is correct
23 Correct 15 ms 24300 KB Output is correct
24 Correct 16 ms 24428 KB Output is correct
25 Correct 16 ms 24556 KB Output is correct
26 Correct 16 ms 24300 KB Output is correct
27 Correct 15 ms 24300 KB Output is correct
28 Correct 506 ms 76396 KB Output is correct
29 Correct 471 ms 74476 KB Output is correct
30 Correct 217 ms 42476 KB Output is correct
31 Correct 548 ms 94956 KB Output is correct
32 Correct 289 ms 55660 KB Output is correct
33 Correct 17 ms 24300 KB Output is correct
34 Correct 218 ms 43628 KB Output is correct
35 Correct 16 ms 24556 KB Output is correct
36 Correct 15 ms 24300 KB Output is correct
37 Correct 16 ms 24300 KB Output is correct
38 Correct 578 ms 82156 KB Output is correct
39 Correct 935 ms 109184 KB Output is correct
40 Correct 15 ms 24300 KB Output is correct
41 Correct 18 ms 24684 KB Output is correct
42 Correct 16 ms 24428 KB Output is correct
43 Correct 17 ms 24684 KB Output is correct
44 Correct 240 ms 46060 KB Output is correct
45 Correct 844 ms 96796 KB Output is correct
46 Correct 15 ms 24300 KB Output is correct