이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
using namespace std;
int h,w;
int t[2010][2010];
int minn=1e9,maxx=0;
bool lewy_min(int sre)
{
int lewo=w;
for(int i=1;i<=h;i++)
{
for(int j=lewo;j>=1;j--)
if(maxx-t[i][j]>sre)
lewo=j-1;
for(int j=lewo+1;j<=w;j++)
if(t[i][j]-minn>sre)
return 0;
}
return 1;
}
bool lewy_maxx(int sre)
{
int lewo=w;
for(int i=1;i<=h;i++)
{
for(int j=lewo;j>=1;j--)
if(t[i][j]-minn>sre)
lewo=j-1;
for(int j=lewo+1;j<=w;j++)
if(maxx-t[i][j]>sre)
return 0;
}
return 1;
}
bool prawo_min(int sre)
{
int prawo=w;
for(int i=h;i>=1;i--)
{
for(int j=prawo;j>=1;j--)
if(maxx-t[i][j]>sre)
prawo=j-1;
for(int j=prawo+1;j<=w;j++)
if(t[i][j]-minn>sre)
return 0;
}
return 1;
}
bool prawo_maxx(int sre)
{
int prawo=w;
for(int i=h;i>=1;i--)
{
for(int j=prawo;j>=1;j--)
if(t[i][j]-minn>sre)
prawo=j-1;
for(int j=prawo+1;j<=w;j++)
if(maxx-t[i][j]>sre)
return 0;
}
return 1;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
cin>>h>>w;
for(int i=1;i<=h;i++)
{
for(int j=1;j<=w;j++)
{
cin>>t[i][j];
maxx=max(maxx,t[i][j]);
minn=min(minn,t[i][j]);
}
}
int pocz=0,kon=1e9+1,sre,ostd=0;
while(pocz<kon)
{
sre=(pocz+kon)/2;
if(lewy_min(sre) || lewy_maxx(sre) || prawo_min(sre) || prawo_maxx(sre))
{
kon=sre;
ostd=sre;
}
else pocz=sre+1;
}
cout<<ostd;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |