# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
81615 | tjdgus4384 | 물탱크 (KOI18_watertank) | C++14 | 3049 ms | 71424 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |