Submission #81615

# Submission time Handle Problem Language Result Execution time Memory
81615 2018-10-25T15:27:15 Z tjdgus4384 None (KOI18_watertank) C++14
60 / 100
3000 ms 71424 KB
#include<cstdio>
#include<algorithm>
using namespace std;

int n, m, h;
int hp[1002][1002];
int vp[1002][1002];
int water[1002][1002];

int main()
{
    scanf("%d %d %d", &n, &m, &h);
    for(int i = 0;i <= n;i++)
    {
        for(int j = 1;j <= m;j++)
        {
            scanf("%d", &hp[i][j]);
            if(hp[i][j] == -1) hp[i][j] = h;
        }
    }
    for(int i = 1;i <= n;i++)
    {
        for(int j = 0;j <= m;j++)
        {
            scanf("%d", &vp[i][j]);
            if(vp[i][j] == -1) vp[i][j] = h;
        }
    }
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= m;j++)
        {
            water[i][j] = h;
        }
    }
    for(int i = 1;i <= n;i++)
    {
        water[i][1] = min(water[i][1], vp[i][0]);
        water[i][m] = min(water[i][m], vp[i][m]);
    }
    for(int i = 1;i <= m;i++)
    {
        water[1][i] = min(water[1][i], hp[0][i]);
        water[n][i] = min(water[n][i], hp[n][i]);
    }
    bool change = true;
    while(change)
    {
        change = false;
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= m;j++)
        {
            int a;
            a = max(water[i][j], vp[i][j - 1]);
            if(water[i][j - 1] > a) {water[i][j - 1] = a; change = true;}
            a = max(water[i][j], vp[i][j]);
            if(water[i][j + 1] > a) {water[i][j + 1] = a; change = true;}
            a = max(water[i][j], hp[i - 1][j]);
            if(water[i - 1][j] > a) {water[i - 1][j] = a; change = true;}
            a = max(water[i][j], hp[i][j]);
            if(water[i + 1][j] > a) {water[i + 1][j] = a; change = true;}
        }
    }
    for(int i = 1;i <= n;i++)
    {
        for(int j = m;j > 0;j--)
        {
            int a;
            a = max(water[i][j], vp[i][j - 1]);
            if(water[i][j - 1] > a) {water[i][j - 1] = a; change = true;}
            a = max(water[i][j], vp[i][j]);
            if(water[i][j + 1] > a) {water[i][j + 1] = a; change = true;}
            a = max(water[i][j], hp[i - 1][j]);
            if(water[i - 1][j] > a) {water[i - 1][j] = a; change = true;}
            a = max(water[i][j], hp[i][j]);
            if(water[i + 1][j] > a) {water[i + 1][j] = a; change = true;}
        }
    }
    for(int i = n;i > 0;i--)
    {
        for(int j = 1;j <= m;j++)
        {
            int a;
            a = max(water[i][j], vp[i][j - 1]);
            if(water[i][j - 1] > a) {water[i][j - 1] = a; change = true;}
            a = max(water[i][j], vp[i][j]);
            if(water[i][j + 1] > a) {water[i][j + 1] = a; change = true;}
            a = max(water[i][j], hp[i - 1][j]);
            if(water[i - 1][j] > a) {water[i - 1][j] = a; change = true;}
            a = max(water[i][j], hp[i][j]);
            if(water[i + 1][j] > a) {water[i + 1][j] = a; change = true;}
        }
    }
    for(int i = n;i > 0;i--)
    {
        for(int j = m;j > 0;j--)
        {
            int a;
            a = max(water[i][j], vp[i][j - 1]);
            if(water[i][j - 1] > a) {water[i][j - 1] = a; change = true;}
            a = max(water[i][j], vp[i][j]);
            if(water[i][j + 1] > a) {water[i][j + 1] = a; change = true;}
            a = max(water[i][j], hp[i - 1][j]);
            if(water[i - 1][j] > a) {water[i - 1][j] = a; change = true;}
            a = max(water[i][j], hp[i][j]);
            if(water[i + 1][j] > a) {water[i + 1][j] = a; change = true;}
        }
    }
    }
    int ans = 0;
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= m;j++)
        {
            ans += water[i][j];
        }
    }
    printf("%d", ans);
    return 0;
}

Compilation message

watertank.cpp: In function 'int main()':
watertank.cpp:12: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", &hp[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~
watertank.cpp:25:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &vp[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 2 ms 508 KB Output is correct
9 Correct 2 ms 508 KB Output is correct
10 Correct 2 ms 508 KB Output is correct
11 Correct 2 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Correct 2 ms 552 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 3 ms 564 KB Output is correct
5 Correct 3 ms 580 KB Output is correct
6 Correct 3 ms 580 KB Output is correct
7 Correct 2 ms 580 KB Output is correct
8 Correct 2 ms 580 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 616 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 271 ms 12500 KB Output is correct
2 Correct 2 ms 12500 KB Output is correct
3 Correct 184 ms 12500 KB Output is correct
4 Correct 217 ms 12500 KB Output is correct
5 Correct 2 ms 12500 KB Output is correct
6 Correct 1680 ms 12500 KB Output is correct
7 Correct 186 ms 16588 KB Output is correct
8 Correct 230 ms 21216 KB Output is correct
9 Correct 180 ms 24988 KB Output is correct
10 Correct 2 ms 24988 KB Output is correct
11 Correct 263 ms 30220 KB Output is correct
12 Correct 2 ms 30220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 30220 KB Output is correct
2 Correct 2 ms 30220 KB Output is correct
3 Correct 2 ms 30220 KB Output is correct
4 Correct 2 ms 30220 KB Output is correct
5 Correct 2 ms 30220 KB Output is correct
6 Correct 2 ms 30220 KB Output is correct
7 Correct 3 ms 30220 KB Output is correct
8 Correct 4 ms 30220 KB Output is correct
9 Correct 2 ms 30220 KB Output is correct
10 Correct 3 ms 30220 KB Output is correct
11 Correct 3 ms 30220 KB Output is correct
12 Correct 2 ms 30220 KB Output is correct
13 Correct 3 ms 30220 KB Output is correct
14 Correct 2 ms 30220 KB Output is correct
15 Correct 2 ms 30220 KB Output is correct
16 Correct 3 ms 30220 KB Output is correct
17 Correct 3 ms 30220 KB Output is correct
18 Correct 3 ms 30220 KB Output is correct
19 Correct 2 ms 30220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 30220 KB Output is correct
2 Correct 2 ms 30220 KB Output is correct
3 Correct 2 ms 30220 KB Output is correct
4 Correct 2 ms 30220 KB Output is correct
5 Correct 2 ms 30220 KB Output is correct
6 Correct 239 ms 30348 KB Output is correct
7 Correct 2 ms 30348 KB Output is correct
8 Correct 2 ms 30348 KB Output is correct
9 Correct 196 ms 30348 KB Output is correct
10 Correct 2 ms 30348 KB Output is correct
11 Correct 2 ms 30348 KB Output is correct
12 Correct 200 ms 30392 KB Output is correct
13 Correct 183 ms 30392 KB Output is correct
14 Correct 2 ms 30392 KB Output is correct
15 Correct 307 ms 30392 KB Output is correct
16 Correct 2 ms 30392 KB Output is correct
17 Correct 2 ms 30392 KB Output is correct
18 Correct 2 ms 30392 KB Output is correct
19 Correct 238 ms 30392 KB Output is correct
20 Correct 3 ms 30392 KB Output is correct
21 Correct 1724 ms 30520 KB Output is correct
22 Correct 5 ms 30520 KB Output is correct
23 Correct 2 ms 30520 KB Output is correct
24 Correct 3 ms 30520 KB Output is correct
25 Correct 3 ms 30520 KB Output is correct
26 Correct 2 ms 30520 KB Output is correct
27 Correct 2 ms 30520 KB Output is correct
28 Correct 2015 ms 37252 KB Output is correct
29 Correct 1509 ms 42256 KB Output is correct
30 Correct 203 ms 46336 KB Output is correct
31 Correct 226 ms 50848 KB Output is correct
32 Correct 246 ms 56420 KB Output is correct
33 Correct 2 ms 56420 KB Output is correct
34 Correct 195 ms 60220 KB Output is correct
35 Correct 3 ms 60220 KB Output is correct
36 Correct 2 ms 60220 KB Output is correct
37 Correct 3 ms 60220 KB Output is correct
38 Correct 297 ms 65648 KB Output is correct
39 Execution timed out 3049 ms 71424 KB Time limit exceeded
40 Halted 0 ms 0 KB -