#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=maxx-minn,sre,ostd;
while(pocz<kon)
{
sre=(pocz+kon)/2;
//cout<<sre<<"\n";
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;
}
Compilation message
joioi.cpp: In function 'int main()':
joioi.cpp:90:11: warning: 'ostd' may be used uninitialized in this function [-Wmaybe-uninitialized]
90 | cout<<ostd;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |