Submission #69610

# Submission time Handle Problem Language Result Execution time Memory
69610 2018-08-21T10:01:07 Z MrTEK The Kingdom of JOIOI (JOI17_joioi) C++14
60 / 100
1503 ms 263168 KB
#include <bits/stdc++.h>

using namespace std;
#define mp make_pair
#define pb push_back
#define len(a) (int)a.size()
#define fi first
#define sc second
#define d1(w) cerr<<#w<<":"<<w<<endl;
#define d2(w,c) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<endl;
#define d3(w,c,z) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<" "<<#z<<":"<<z<<endl;
#define left isc+isc
#define right isc+isc+1
#define mid (l+r)/2
#define FAfi_IO ios_base::sync_with_fidio(false);
#define escl '\n'

typedef long long int ll;

const int maxn = 620;
const long long LINF = 1e18;
const int LOG = 31;
const int INF = 1e9;
const int N = 2e3 + 5;
const int M = 1e4 + 5;
const int SQ = 350;
const int MOD = 998244353;

typedef long long int lli;
typedef pair<int,int> pii;


int n,m,a[N][N],mn = INF,mx = -INF,ans;

void flip_row() {
	for (int i = 1 ; i <= n / 2 ; i++)
		for (int j = 1 ; j <= m ; j++)
			swap(a[i][j],a[n - i + 1][j]);
}

void flip_col() {
	for (int i = 1 ; i <= n ; i++)
		for (int j = 1 ; j <= m / 2 ; j++)
			swap(a[i][j],a[i][m - j + 1]);
}

bool check (int val) {

	int mxj = 1;
	for (int i = 1 ; i <= n; i++) {
		for (int j = 1 ; j <= m ; j++) {
			if (a[i][j] < mx - val)
				mxj = max(mxj,j + 1);
		}
		for (int j = 1 ; j <= m ; j++)
			if (a[i][j] > mn + val && mxj > j)
				return false; 
	}
	return true;
}

void print() {
	printf("\n\n\n");
	for (int i = 1 ; i <= n ; i++,puts(""))
		for (int j = 1 ; j <= m ; j++)
			printf("%d ",a[i][j]);
	printf("\n\n\n");
}

int solve() {
	int l = 0 , r = mx - mn;
	while (l < r) {
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	return l;
}

int main() {
	scanf("%d %d",&n,&m);
	for (int i = 1 ; i <= n ; i++)
		for (int j = 1 ; j <= m ; j++) {
			scanf("%d",&a[i][j]);
			mn = min(a[i][j],mn);
			mx = max(a[i][j],mx);
		}
	ans = solve();
	flip_row();
	// print();
	ans = min(ans,solve());
	flip_col();
	// print();
	ans = min(ans,solve());
	flip_row();
	// print();
	ans = min(ans,solve());
	printf("%d\n",ans);
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:80: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:83: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 3 ms 248 KB Output is correct
2 Correct 2 ms 524 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 3 ms 648 KB Output is correct
8 Correct 2 ms 648 KB Output is correct
9 Correct 2 ms 648 KB Output is correct
10 Correct 3 ms 648 KB Output is correct
11 Correct 3 ms 648 KB Output is correct
12 Correct 2 ms 776 KB Output is correct
13 Correct 2 ms 776 KB Output is correct
14 Correct 2 ms 776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 524 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 3 ms 648 KB Output is correct
8 Correct 2 ms 648 KB Output is correct
9 Correct 2 ms 648 KB Output is correct
10 Correct 3 ms 648 KB Output is correct
11 Correct 3 ms 648 KB Output is correct
12 Correct 2 ms 776 KB Output is correct
13 Correct 2 ms 776 KB Output is correct
14 Correct 2 ms 776 KB Output is correct
15 Correct 3 ms 776 KB Output is correct
16 Correct 8 ms 1800 KB Output is correct
17 Correct 13 ms 2020 KB Output is correct
18 Correct 13 ms 2308 KB Output is correct
19 Correct 15 ms 2576 KB Output is correct
20 Correct 13 ms 2720 KB Output is correct
21 Correct 19 ms 3192 KB Output is correct
22 Correct 16 ms 3620 KB Output is correct
23 Correct 21 ms 3956 KB Output is correct
24 Correct 19 ms 4264 KB Output is correct
25 Correct 31 ms 4740 KB Output is correct
26 Correct 18 ms 5124 KB Output is correct
27 Correct 15 ms 5512 KB Output is correct
28 Correct 14 ms 5900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 524 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 3 ms 648 KB Output is correct
8 Correct 2 ms 648 KB Output is correct
9 Correct 2 ms 648 KB Output is correct
10 Correct 3 ms 648 KB Output is correct
11 Correct 3 ms 648 KB Output is correct
12 Correct 2 ms 776 KB Output is correct
13 Correct 2 ms 776 KB Output is correct
14 Correct 2 ms 776 KB Output is correct
15 Correct 3 ms 776 KB Output is correct
16 Correct 8 ms 1800 KB Output is correct
17 Correct 13 ms 2020 KB Output is correct
18 Correct 13 ms 2308 KB Output is correct
19 Correct 15 ms 2576 KB Output is correct
20 Correct 13 ms 2720 KB Output is correct
21 Correct 19 ms 3192 KB Output is correct
22 Correct 16 ms 3620 KB Output is correct
23 Correct 21 ms 3956 KB Output is correct
24 Correct 19 ms 4264 KB Output is correct
25 Correct 31 ms 4740 KB Output is correct
26 Correct 18 ms 5124 KB Output is correct
27 Correct 15 ms 5512 KB Output is correct
28 Correct 14 ms 5900 KB Output is correct
29 Correct 763 ms 41880 KB Output is correct
30 Correct 831 ms 64300 KB Output is correct
31 Correct 940 ms 87580 KB Output is correct
32 Correct 763 ms 110580 KB Output is correct
33 Correct 672 ms 128620 KB Output is correct
34 Correct 929 ms 153788 KB Output is correct
35 Correct 1434 ms 192772 KB Output is correct
36 Correct 1130 ms 226224 KB Output is correct
37 Runtime error 1503 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.