Submission #480730

# Submission time Handle Problem Language Result Execution time Memory
480730 2021-10-18T01:24:32 Z MonkeyKing The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
707 ms 31812 KB
//Original Code:
//#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)
//{
//	int x=mn.first,y=mx.first;
//	int pre=m;
//	for(int i=0;i<n;i++)
//	{
//		for(int j=0;j<pre;j++)
//		{
//			if(a[i][j]-x>mid)
//			{
//				pre=j;
//				break;
//			}
//		}
//		for(int j=pre;j<m;j++)
//		{
//			if(y-a[i][j]>mid) 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;
//}

//substituted with C++ Inliner
#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)
{
	int x=mn.first,y=mx.first;
	int pre=m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<pre;j++)
		{
			if(a[i][j]-x>mid)
			{
				pre=j;
				break;
			}
		}
		for(int j=pre;j<m;j++)
		{
			if(y-a[i][j]>mid) 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:201:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  201 |   mid=l+r>>1;
      |       ~^~
joioi.cpp: In function 'int main()':
joioi.cpp:224:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  224 |    scanf("%d",a[i]+j);
      |    ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 15996 KB Output is correct
2 Correct 15 ms 16036 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 16020 KB Output is correct
6 Correct 15 ms 16056 KB Output is correct
7 Correct 16 ms 16056 KB Output is correct
8 Correct 15 ms 16076 KB Output is correct
9 Correct 16 ms 16076 KB Output is correct
10 Correct 15 ms 16076 KB Output is correct
11 Correct 15 ms 15976 KB Output is correct
12 Correct 16 ms 16168 KB Output is correct
13 Correct 16 ms 16084 KB Output is correct
14 Correct 16 ms 16076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 15996 KB Output is correct
2 Correct 15 ms 16036 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 16020 KB Output is correct
6 Correct 15 ms 16056 KB Output is correct
7 Correct 16 ms 16056 KB Output is correct
8 Correct 15 ms 16076 KB Output is correct
9 Correct 16 ms 16076 KB Output is correct
10 Correct 15 ms 16076 KB Output is correct
11 Correct 15 ms 15976 KB Output is correct
12 Correct 16 ms 16168 KB Output is correct
13 Correct 16 ms 16084 KB Output is correct
14 Correct 16 ms 16076 KB Output is correct
15 Correct 17 ms 16972 KB Output is correct
16 Correct 18 ms 16972 KB Output is correct
17 Correct 20 ms 16972 KB Output is correct
18 Correct 21 ms 17028 KB Output is correct
19 Correct 19 ms 16968 KB Output is correct
20 Correct 20 ms 17016 KB Output is correct
21 Correct 21 ms 17012 KB Output is correct
22 Correct 23 ms 17028 KB Output is correct
23 Correct 24 ms 16960 KB Output is correct
24 Correct 22 ms 16972 KB Output is correct
25 Correct 23 ms 16936 KB Output is correct
26 Correct 23 ms 17020 KB Output is correct
27 Correct 23 ms 16944 KB Output is correct
28 Correct 21 ms 16972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 15996 KB Output is correct
2 Correct 15 ms 16036 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 16020 KB Output is correct
6 Correct 15 ms 16056 KB Output is correct
7 Correct 16 ms 16056 KB Output is correct
8 Correct 15 ms 16076 KB Output is correct
9 Correct 16 ms 16076 KB Output is correct
10 Correct 15 ms 16076 KB Output is correct
11 Correct 15 ms 15976 KB Output is correct
12 Correct 16 ms 16168 KB Output is correct
13 Correct 16 ms 16084 KB Output is correct
14 Correct 16 ms 16076 KB Output is correct
15 Correct 17 ms 16972 KB Output is correct
16 Correct 18 ms 16972 KB Output is correct
17 Correct 20 ms 16972 KB Output is correct
18 Correct 21 ms 17028 KB Output is correct
19 Correct 19 ms 16968 KB Output is correct
20 Correct 20 ms 17016 KB Output is correct
21 Correct 21 ms 17012 KB Output is correct
22 Correct 23 ms 17028 KB Output is correct
23 Correct 24 ms 16960 KB Output is correct
24 Correct 22 ms 16972 KB Output is correct
25 Correct 23 ms 16936 KB Output is correct
26 Correct 23 ms 17020 KB Output is correct
27 Correct 23 ms 16944 KB Output is correct
28 Correct 21 ms 16972 KB Output is correct
29 Correct 496 ms 31620 KB Output is correct
30 Correct 491 ms 31764 KB Output is correct
31 Correct 543 ms 31812 KB Output is correct
32 Correct 490 ms 31724 KB Output is correct
33 Correct 454 ms 31592 KB Output is correct
34 Correct 493 ms 31708 KB Output is correct
35 Correct 640 ms 31728 KB Output is correct
36 Correct 585 ms 31552 KB Output is correct
37 Correct 707 ms 31712 KB Output is correct