답안 #254573

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
254573 2020-07-30T09:45:02 Z babo The Kingdom of JOIOI (JOI17_joioi) C++14
60 / 100
4000 ms 102504 KB
#include <bits/stdc++.h>
#define L long long

using namespace std;

L n,m;
L totma=0,totmi=1000000000ll;
L a[2020][2020];
L c[2020][2020];
L rowma[2020],rowmi[2020];
L colma[2020],colmi[2020];

void clear(){
	L i;
	for(i=1;i<=n;i++)
		rowma[i]=0,rowmi[i]=1000000000ll;
	for(i=1;i<=m;i++)
		colma[i]=0,colmi[i]=1000000000ll;
}

void clear2(){
	L i,j;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			c[i][j]=0;
}

bool ok2(L dis){
	L mamin=1000000000ll,mimax=0;
	L i,j;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
		{
			if(c[i][j]) mamin=min(mamin,a[i][j]);
			else mimax=max(mimax,a[i][j]);
		}
	return totma-mamin<=dis&&mimax-totmi<=dis;
}

bool ok(L dis){
	L i,j;
	clear();
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			if(a[i][j]>totmi+dis)
			{
				rowma[i]=max(rowma[i],j);
				rowmi[i]=min(rowmi[i],j);
				colma[j]=max(colma[j],i);
				colmi[j]=min(colmi[j],i);
			}
	L now;
	clear2();
	now=n+1;
	for(j=m;j>=1;j--)
	{
		now=min(now,colmi[j]);
		for(i=now;i<=n;i++) c[i][j]=1;
	}
	if(ok2(dis)) return 1;
	clear2();
	now=n+1;
	for(j=1;j<=m;j++)
	{
		now=min(now,colmi[j]);
		for(i=now;i<=n;i++) c[i][j]=1;
	}
	if(ok2(dis)) return 1;
	clear2();
	now=0;
	for(j=1;j<=m;j++)
	{
		now=max(now,colma[j]);
		for(i=1;i<=now;i++) c[i][j]=1;
	}
	if(ok2(dis)) return 1;
	clear2();
	now=0;
	for(j=m;j>=1;j--)
	{
		now=max(now,colma[j]);
		for(i=1;i<=now;i++) c[i][j]=1;
	}
	if(ok2(dis)) return 1;

	return 0;
}

int main()
{
	scanf("%lld %lld",&n,&m);
	L i,j;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			scanf("%lld",&a[i][j]);
			totma=max(totma,a[i][j]);
			totmi=min(totmi,a[i][j]);
		}
	}
	L s=0,e=1000000000ll;
	while(s<e)
	{
		L mid=(s+e)/2;
		if(ok(mid)) e=mid;
		else s=mid+1;
	}
	printf("%lld",s);
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:91:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~~~~~
joioi.cpp:97:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld",&a[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 9 ms 2560 KB Output is correct
17 Correct 16 ms 2816 KB Output is correct
18 Correct 17 ms 2816 KB Output is correct
19 Correct 25 ms 2816 KB Output is correct
20 Correct 17 ms 2560 KB Output is correct
21 Correct 19 ms 2936 KB Output is correct
22 Correct 24 ms 2944 KB Output is correct
23 Correct 21 ms 2944 KB Output is correct
24 Correct 19 ms 2688 KB Output is correct
25 Correct 28 ms 3040 KB Output is correct
26 Correct 22 ms 3040 KB Output is correct
27 Correct 20 ms 2944 KB Output is correct
28 Correct 22 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 9 ms 2560 KB Output is correct
17 Correct 16 ms 2816 KB Output is correct
18 Correct 17 ms 2816 KB Output is correct
19 Correct 25 ms 2816 KB Output is correct
20 Correct 17 ms 2560 KB Output is correct
21 Correct 19 ms 2936 KB Output is correct
22 Correct 24 ms 2944 KB Output is correct
23 Correct 21 ms 2944 KB Output is correct
24 Correct 19 ms 2688 KB Output is correct
25 Correct 28 ms 3040 KB Output is correct
26 Correct 22 ms 3040 KB Output is correct
27 Correct 20 ms 2944 KB Output is correct
28 Correct 22 ms 2944 KB Output is correct
29 Correct 3579 ms 82632 KB Output is correct
30 Correct 3951 ms 85220 KB Output is correct
31 Correct 3526 ms 86812 KB Output is correct
32 Correct 3583 ms 86792 KB Output is correct
33 Correct 2587 ms 76004 KB Output is correct
34 Correct 3909 ms 86928 KB Output is correct
35 Execution timed out 4072 ms 102504 KB Time limit exceeded
36 Halted 0 ms 0 KB -