Submission #480729

# Submission time Handle Problem Language Result Execution time Memory
480729 2021-10-18T01:22:33 Z MonkeyKing The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
2403 ms 47572 KB
#include <numeric>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#include <time.h>
#define Endl endl
#define mp make_pair
#define mt make_tuple
#define ll long long 
#define ull unsigned long long
#define pii pair<int,int>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define quickcin ios_base::sync_with_stdio(false);
const int mod=1000000007;
const int gmod=3;
const int inf=1039074182;
const double eps=1e-9;
const double pi=3.141592653589793238462643383279;
const ll llinf=2LL*inf*inf;
template <typename T1,typename T2> inline void chmin(T1 &x,T2 b) {if(b<x) x=b;}
template <typename T1,typename T2> inline void chmax(T1 &x,T2 b) {if(b>x) x=b;}
inline void chadd(int &x,int b) {x+=b-mod;x+=(x>>31 & mod);}
template <typename T1,typename T2> inline void chadd(T1 &x,T2 b) {x+=b;if(x>=mod) x-=mod;}
template <typename T1,typename T2> inline void chmul(T1 &x,T2 b) {x=1LL*x*b%mod;}
template <typename T1,typename T2> inline void chmod(T1 &x,T2 b) {x%=b,x+=b;if(x>=b) x-=b;}
template <typename T> inline T mabs(T x) {return (x<0?-x:x);}
using namespace std;
int n,m;
int a[2005][2005];
int b[2005][2005];
int bel[2005][2005];
pair<int,pii> mn,mx;
int res;

inline bool check(int mid)
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			bel[i][j]=0;
			if(a[i][j]-mn.first<=mid) bel[i][j]|=1;
			if(mx.first-a[i][j]<=mid) bel[i][j]|=2;
			if(!bel[i][j]) return 0;
		}
	}
	int pre=m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<pre;j++)
		{
			if(bel[i][j]==2)
			{
				pre=j;
				break;
			}
		}
		for(int j=pre;j<m;j++)
		{
			if(bel[i][j]==1) return false;
		}
	}
	return true;
}

void solve()
{
	if(mn.first>=mx.first && mn.second>=mx.second) return;
	int l=0,r=res-1,mid;
	while(l<=r)
	{
		mid=l+r>>1;
		if(check(mid))
		{
			res=mid;
			r=mid-1;
		}
		else
		{
			l=mid+1;
		}
	}
}

int main()
{
	// freopen("input.txt","r",stdin);
	cin>>n>>m;
	mn.first=inf;
	mx.first=-inf;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			scanf("%d",a[i]+j);
			chmax(mx,mp(a[i][j],mp(i,j)));
			chmin(mn,mp(a[i][j],mp(i,j)));
		}
	}
	res=mx.first-mn.first;
	for(int _=0;_<4;_++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				b[j][n-1-i]=a[i][j];
			}
		}
		memcpy(a,b,sizeof(b));
		swap(mx.second.first,mx.second.second);
		mx.second.second=n-1-mx.second.second;
		swap(mn.second.first,mn.second.second);
		mn.second.second=n-1-mn.second.second;
		swap(n,m);
		solve();
	}
	cout<<res<<endl;
	return 0;
}

Compilation message

joioi.cpp: In function 'void solve()':
joioi.cpp:84:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   84 |   mid=l+r>>1;
      |       ~^~
joioi.cpp: In function 'int main()':
joioi.cpp:107:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |    scanf("%d",a[i]+j);
      |    ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16076 KB Output is correct
2 Correct 16 ms 16088 KB Output is correct
3 Correct 15 ms 16076 KB Output is correct
4 Correct 15 ms 16076 KB Output is correct
5 Correct 15 ms 16088 KB Output is correct
6 Correct 15 ms 16076 KB Output is correct
7 Correct 16 ms 16048 KB Output is correct
8 Correct 15 ms 16044 KB Output is correct
9 Correct 15 ms 16036 KB Output is correct
10 Correct 18 ms 16052 KB Output is correct
11 Correct 15 ms 16076 KB Output is correct
12 Correct 15 ms 16044 KB Output is correct
13 Correct 16 ms 16140 KB Output is correct
14 Correct 15 ms 16060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16076 KB Output is correct
2 Correct 16 ms 16088 KB Output is correct
3 Correct 15 ms 16076 KB Output is correct
4 Correct 15 ms 16076 KB Output is correct
5 Correct 15 ms 16088 KB Output is correct
6 Correct 15 ms 16076 KB Output is correct
7 Correct 16 ms 16048 KB Output is correct
8 Correct 15 ms 16044 KB Output is correct
9 Correct 15 ms 16036 KB Output is correct
10 Correct 18 ms 16052 KB Output is correct
11 Correct 15 ms 16076 KB Output is correct
12 Correct 15 ms 16044 KB Output is correct
13 Correct 16 ms 16140 KB Output is correct
14 Correct 15 ms 16060 KB Output is correct
15 Correct 16 ms 17612 KB Output is correct
16 Correct 22 ms 17980 KB Output is correct
17 Correct 28 ms 18232 KB Output is correct
18 Correct 25 ms 18124 KB Output is correct
19 Correct 32 ms 18124 KB Output is correct
20 Correct 30 ms 18192 KB Output is correct
21 Correct 34 ms 18252 KB Output is correct
22 Correct 30 ms 18472 KB Output is correct
23 Correct 37 ms 18264 KB Output is correct
24 Correct 27 ms 18300 KB Output is correct
25 Correct 40 ms 18364 KB Output is correct
26 Correct 29 ms 18260 KB Output is correct
27 Correct 33 ms 18360 KB Output is correct
28 Correct 33 ms 18360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16076 KB Output is correct
2 Correct 16 ms 16088 KB Output is correct
3 Correct 15 ms 16076 KB Output is correct
4 Correct 15 ms 16076 KB Output is correct
5 Correct 15 ms 16088 KB Output is correct
6 Correct 15 ms 16076 KB Output is correct
7 Correct 16 ms 16048 KB Output is correct
8 Correct 15 ms 16044 KB Output is correct
9 Correct 15 ms 16036 KB Output is correct
10 Correct 18 ms 16052 KB Output is correct
11 Correct 15 ms 16076 KB Output is correct
12 Correct 15 ms 16044 KB Output is correct
13 Correct 16 ms 16140 KB Output is correct
14 Correct 15 ms 16060 KB Output is correct
15 Correct 16 ms 17612 KB Output is correct
16 Correct 22 ms 17980 KB Output is correct
17 Correct 28 ms 18232 KB Output is correct
18 Correct 25 ms 18124 KB Output is correct
19 Correct 32 ms 18124 KB Output is correct
20 Correct 30 ms 18192 KB Output is correct
21 Correct 34 ms 18252 KB Output is correct
22 Correct 30 ms 18472 KB Output is correct
23 Correct 37 ms 18264 KB Output is correct
24 Correct 27 ms 18300 KB Output is correct
25 Correct 40 ms 18364 KB Output is correct
26 Correct 29 ms 18260 KB Output is correct
27 Correct 33 ms 18360 KB Output is correct
28 Correct 33 ms 18360 KB Output is correct
29 Correct 1060 ms 47572 KB Output is correct
30 Correct 1433 ms 47420 KB Output is correct
31 Correct 2009 ms 47400 KB Output is correct
32 Correct 1036 ms 47380 KB Output is correct
33 Correct 836 ms 47228 KB Output is correct
34 Correct 1580 ms 47416 KB Output is correct
35 Correct 1422 ms 47368 KB Output is correct
36 Correct 967 ms 47216 KB Output is correct
37 Correct 2403 ms 47432 KB Output is correct