답안 #51527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51527 2018-06-18T07:10:43 Z MoesashiMinamoto The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
3 ms 624 KB
#include <bits/stdc++.h>

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("%d%d", &h[0], &w[0]);
	mi = INT_MAX;
	for (int i = 1; i <= h[0]; i++)
	{
		for (int j = 1; j <= w[0]; j++)
		{
			scanf("%d", &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("%d", 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("%d%d", &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("%d", &a[0][i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 624 KB Output is correct
3 Incorrect 2 ms 624 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 624 KB Output is correct
3 Incorrect 2 ms 624 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 624 KB Output is correct
3 Incorrect 2 ms 624 KB Output isn't correct
4 Halted 0 ms 0 KB -