Submission #81608

#TimeUsernameProblemLanguageResultExecution timeMemory
81608tjdgus4384물탱크 (KOI18_watertank)C++14
24 / 100
254 ms27448 KiB
#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]);
    }
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= m;j++)
        {
            water[i][j] = min(water[i][j], max(water[i][j - 1], vp[i][j - 1]));
            water[i][j] = min(water[i][j], max(water[i][j + 1], vp[i][j]));
            water[i][j] = min(water[i][j], max(water[i - 1][j], hp[i - 1][j]));
            water[i][j] = min(water[i][j], max(water[i + 1][j], hp[i][j]));
        }
    }
    for(int i = 1;i <= n;i++)
    {
        for(int j = m;j > 0;j--)
        {
            water[i][j] = min(water[i][j], max(water[i][j - 1], vp[i][j - 1]));
            water[i][j] = min(water[i][j], max(water[i][j + 1], vp[i][j]));
            water[i][j] = min(water[i][j], max(water[i - 1][j], hp[i - 1][j]));
            water[i][j] = min(water[i][j], max(water[i + 1][j], hp[i][j]));
        }
    }
    for(int i = n;i > 0;i--)
    {
        for(int j = 1;j <= m;j++)
        {
            water[i][j] = min(water[i][j], max(water[i][j - 1], vp[i][j - 1]));
            water[i][j] = min(water[i][j], max(water[i][j + 1], vp[i][j]));
            water[i][j] = min(water[i][j], max(water[i - 1][j], hp[i - 1][j]));
            water[i][j] = min(water[i][j], max(water[i + 1][j], hp[i][j]));
        }
    }
    for(int i = n;i > 0;i--)
    {
        for(int j = m;j > 0;j--)
        {
            water[i][j] = min(water[i][j], max(water[i][j - 1], vp[i][j - 1]));
            water[i][j] = min(water[i][j], max(water[i][j + 1], vp[i][j]));
            water[i][j] = min(water[i][j], max(water[i - 1][j], hp[i - 1][j]));
            water[i][j] = min(water[i][j], max(water[i + 1][j], hp[i][j]));
        }
    }
    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 (stderr)

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 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...