Submission #83479

# Submission time Handle Problem Language Result Execution time Memory
83479 2018-11-08T09:49:11 Z ekrem The Kingdom of JOIOI (JOI17_joioi) C++
0 / 100
2 ms 876 KB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define orta ((bas+son)/2)
#define inf 1000000000
#define N 2005
using namespace std;

int n, m, bas, ans = inf, son, a[N][N], mx[N][N], mn[N][N];

void cevir();
void hazirla();

bool dene(int frk){
	int bas = 0, emn = inf, emx = 0, sumn = inf, sumx = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= bas; j++){
			emn = min(emn, a[i][j]);
			emx = max(emx, a[i][j]);
		}
		if(emx - emn > frk)
			return 0;
		for(; bas <= n; bas++){
			if((bas == n or max(mx[i][bas+1],sumx)-min(mn[i][bas+1],sumn)<=frk) and (!bas or emx - emn <= frk) )
				break;
			emn = min(emn, a[i][bas + 1]);
			emx = max(emx, a[i][bas + 1]);
		}
		if(bas > n)
			return 0;
		sumx = max(sumx, mx[i][bas + 1]);
		sumn = min(sumn, mn[i][bas + 1]);
	}
	return (bas <= n);
}

void coz(){
	hazirla();
	bas = 0;
	son = inf;
	while(bas < son){
		if(dene(orta))
			son = orta;
		else
			bas = orta + 1;
	}
	ans = min(ans, orta);
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d",&n ,&m);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			scanf("%d",&a[i][j]);
	coz();
	cevir();
	coz();
	printf("%d\n", ans);
	return 0;
}

















void cevir(){
	for(int i = 1; i <= n; i++)
		reverse(a[i] + 1, a[i] + m + 1);
}

void hazirla(){
	for(int i = 1; i <= n; i++){
		mn[i][m + 1] = inf;
		for(int j = m; j >= 1; j--){
			mn[i][j] = min(a[i][j], mn[i][j + 1]);
			mx[i][j] = max(a[i][j], mx[i][j + 1]);
		}
	}
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n ,&m);
  ~~~~~^~~~~~~~~~~~~~~~
joioi.cpp:58:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&a[i][j]);
    ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 528 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 704 KB Output is correct
5 Correct 2 ms 876 KB Output is correct
6 Correct 2 ms 876 KB Output is correct
7 Correct 2 ms 876 KB Output is correct
8 Correct 2 ms 876 KB Output is correct
9 Correct 2 ms 876 KB Output is correct
10 Incorrect 2 ms 876 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 528 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 704 KB Output is correct
5 Correct 2 ms 876 KB Output is correct
6 Correct 2 ms 876 KB Output is correct
7 Correct 2 ms 876 KB Output is correct
8 Correct 2 ms 876 KB Output is correct
9 Correct 2 ms 876 KB Output is correct
10 Incorrect 2 ms 876 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 528 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 704 KB Output is correct
5 Correct 2 ms 876 KB Output is correct
6 Correct 2 ms 876 KB Output is correct
7 Correct 2 ms 876 KB Output is correct
8 Correct 2 ms 876 KB Output is correct
9 Correct 2 ms 876 KB Output is correct
10 Incorrect 2 ms 876 KB Output isn't correct
11 Halted 0 ms 0 KB -