Submission #51528

# Submission time Handle Problem Language Result Execution time Memory
51528 2018-06-18T07:12:23 Z MoesashiMinamoto The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
2 ms 520 KB
#include <bits/stdc++.h>
#define int 	long long
using namespace std;

int h[4], w[4];
int a[4][2003][2003];
int mi;

void preproc()
{
	for(int t = 1; t < 4; t++)
	{
		h[t] = w[t-1];
		w[t] = h[t-1];
		for (int i = 1; i <= h[t-1]; i++)
		{
			for (int j = 1; j <= w[t-1]; j++)
			{
				a[t][j][h[t-1]-i+1] = a[t-1][i][j];
			}
		}
	}
}

bool chec(int k)
{
	for (int t = 0; t < 4; t++)
	{
		int lim, nexlim = w[t];
		int ma = -INT_MAX, mii = INT_MAX;
		for (int i = 1; i <= h[t]; i++)
		{
			lim = nexlim;
			for (int j = 1; j <= lim; j++)
			{
				if (a[t][i][j] <= mi + k)
				{
					continue;
				}
				else
				{
					nexlim = j-1;
					break;
				}
			}
			for (int j = lim+1; j <= w[t]; j++)
			{
				mii = min(mii, a[t][i][j]);
				ma = max(ma, a[t][i][j]);
			}	
		}
		if (ma - mii <= k) return true;
	}
	return false;
}

signed main()
{
	scanf("%lld%lld", &h[0], &w[0]);
	mi = INT_MAX;
	for (int i = 1; i <= h[0]; i++)
	{
		for (int j = 1; j <= w[0]; j++)
		{
			scanf("%lld", &a[0][i][j]);
			mi = min(mi, a[0][i][j]);
		}
	}	
	preproc();
	/*for (int t = 0; t < 4; t++)
	{
		for (int i = 1; i <= h[t]; i++)
		{
			for (int j = 1; j <= w[t]; j++)
			{
				printf ("%d ", a[t][i][j]);
			}
			printf("\n");
		}
		printf("\n");
	}*/
	int res = 0;
	for (int j = 33; j >= 0; j--)
	{
		if (res + (1ll << j) <= 1000000000)
		{
			int cur = res + (1ll << j);
			if (!chec(cur))
			{
				res = cur;
			}
		}
	}
	printf("%lld", res+1);
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &h[0], &w[0]);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
joioi.cpp:65:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld", &a[0][i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Incorrect 2 ms 520 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Incorrect 2 ms 520 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Incorrect 2 ms 520 KB Output isn't correct
4 Halted 0 ms 0 KB -