Submission #322428

# Submission time Handle Problem Language Result Execution time Memory
322428 2020-11-14T17:34:41 Z Seanliu The Kingdom of JOIOI (JOI17_joioi) C++14
60 / 100
2759 ms 262148 KB
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#define ericxiao ios_base::sync_with_stdio(0);cin.tie(0);
#define pii pair<int,int>
#define F first
#define S second
using namespace std;

const int maxN = 2e3 + 326, INF = 2e9 + 326;

int N, M, arr[maxN][maxN], narr[maxN][maxN], cnt[maxN * maxN], sz;
vector<int> lisan;
vector<pii> pos[maxN * maxN];
bool vis[maxN][maxN];

void take(int y, int x, int &mx, int &mn){
	for(int i = y; i >= 0 && !vis[i][x]; i--){
		for(int j = x; j >= 0 && !vis[i][j]; j--){
			vis[i][j] = true;
			cnt[arr[i][j]]--;
			mx = max(mx, arr[i][j]);
			mn = min(mn, arr[i][j]);
		}
	}
}

void rot(){
	//(i, j) -> (j, N - 1 - i)
	for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) {
		narr[j][N - 1 - i] = arr[i][j];
		vis[i][j] = false;
	}
	for(int i = 0; i < sz; i++) for(auto &[y, x] : pos[i]){
		swap(y, x);
		cnt[i] = 0;
		x = N - 1 - x;	
	}
	for(int i = 0; i < M; i++) for(int j = 0; j < N; j++){
		arr[i][j] = narr[i][j];
		cnt[arr[i][j]]++;
	}
	swap(N, M);
}

int main(){
	ericxiao;
	cin >> N >> M;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			cin >> arr[i][j];
			lisan.push_back(arr[i][j]);
		}
	}
	sort(lisan.begin(), lisan.end());
	sz = unique(lisan.begin(), lisan.end()) - lisan.begin();
	for(int i = 0; i < N; i++) for(int j = 0; j < M; j++){
		arr[i][j] = lower_bound(lisan.begin(), lisan.begin() + sz, arr[i][j]) - lisan.begin();
		cnt[arr[i][j]]++;
		pos[arr[i][j]].emplace_back(i, j);
	}
	int ans = lisan[sz - 1] - lisan[0];
	for(int jizz = 0; jizz < 4; jizz++){
		//cout << "in jizz = " << jizz << endl;
		int mx = -INF, mn = INF, f = 0, e = sz - 1;
		for(int i = 0; i < sz; i++){
			//take all of them
			//
			//cout << "i = " << i << ", = " << lisan[i] << endl;
			for(auto [y, x] : pos[i]){
				take(y, x, mx, mn);
			}
			/*
			for(int y = 0; y < N; y++) for(int x = 0; x < M; x++){
				cout << vis[y][x] << " \n"[x == M - 1];
			}
			*/
			while(f < sz - 1 && !cnt[f]) f++;
			while(e && !cnt[e]) e--;
			if(f == sz || !e) break;
			ans = min(ans, max(lisan[e] - lisan[f], lisan[mx] - lisan[mn]));
			//cout << "ans = " << ans << endl;
		}
		rot();
	}
	cout << ans << endl;
}

Compilation message

joioi.cpp: In function 'void rot()':
joioi.cpp:35:40: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   35 |  for(int i = 0; i < sz; i++) for(auto &[y, x] : pos[i]){
      |                                        ^
joioi.cpp: In function 'int main()':
joioi.cpp:71:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   71 |    for(auto [y, x] : pos[i]){
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 74 ms 127468 KB Output is correct
2 Correct 76 ms 127468 KB Output is correct
3 Correct 75 ms 127468 KB Output is correct
4 Correct 74 ms 127468 KB Output is correct
5 Correct 77 ms 127596 KB Output is correct
6 Correct 74 ms 127468 KB Output is correct
7 Correct 75 ms 127596 KB Output is correct
8 Correct 76 ms 127468 KB Output is correct
9 Correct 77 ms 127468 KB Output is correct
10 Correct 76 ms 127468 KB Output is correct
11 Correct 74 ms 127468 KB Output is correct
12 Correct 75 ms 127468 KB Output is correct
13 Correct 74 ms 127468 KB Output is correct
14 Correct 74 ms 127468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 127468 KB Output is correct
2 Correct 76 ms 127468 KB Output is correct
3 Correct 75 ms 127468 KB Output is correct
4 Correct 74 ms 127468 KB Output is correct
5 Correct 77 ms 127596 KB Output is correct
6 Correct 74 ms 127468 KB Output is correct
7 Correct 75 ms 127596 KB Output is correct
8 Correct 76 ms 127468 KB Output is correct
9 Correct 77 ms 127468 KB Output is correct
10 Correct 76 ms 127468 KB Output is correct
11 Correct 74 ms 127468 KB Output is correct
12 Correct 75 ms 127468 KB Output is correct
13 Correct 74 ms 127468 KB Output is correct
14 Correct 74 ms 127468 KB Output is correct
15 Correct 75 ms 129516 KB Output is correct
16 Correct 83 ms 130416 KB Output is correct
17 Correct 101 ms 131440 KB Output is correct
18 Correct 95 ms 131312 KB Output is correct
19 Correct 108 ms 131312 KB Output is correct
20 Correct 107 ms 131188 KB Output is correct
21 Correct 97 ms 131312 KB Output is correct
22 Correct 95 ms 131440 KB Output is correct
23 Correct 97 ms 131312 KB Output is correct
24 Correct 96 ms 131184 KB Output is correct
25 Correct 108 ms 131312 KB Output is correct
26 Correct 115 ms 131312 KB Output is correct
27 Correct 98 ms 131440 KB Output is correct
28 Correct 98 ms 131312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 127468 KB Output is correct
2 Correct 76 ms 127468 KB Output is correct
3 Correct 75 ms 127468 KB Output is correct
4 Correct 74 ms 127468 KB Output is correct
5 Correct 77 ms 127596 KB Output is correct
6 Correct 74 ms 127468 KB Output is correct
7 Correct 75 ms 127596 KB Output is correct
8 Correct 76 ms 127468 KB Output is correct
9 Correct 77 ms 127468 KB Output is correct
10 Correct 76 ms 127468 KB Output is correct
11 Correct 74 ms 127468 KB Output is correct
12 Correct 75 ms 127468 KB Output is correct
13 Correct 74 ms 127468 KB Output is correct
14 Correct 74 ms 127468 KB Output is correct
15 Correct 75 ms 129516 KB Output is correct
16 Correct 83 ms 130416 KB Output is correct
17 Correct 101 ms 131440 KB Output is correct
18 Correct 95 ms 131312 KB Output is correct
19 Correct 108 ms 131312 KB Output is correct
20 Correct 107 ms 131188 KB Output is correct
21 Correct 97 ms 131312 KB Output is correct
22 Correct 95 ms 131440 KB Output is correct
23 Correct 97 ms 131312 KB Output is correct
24 Correct 96 ms 131184 KB Output is correct
25 Correct 108 ms 131312 KB Output is correct
26 Correct 115 ms 131312 KB Output is correct
27 Correct 98 ms 131440 KB Output is correct
28 Correct 98 ms 131312 KB Output is correct
29 Correct 2193 ms 252612 KB Output is correct
30 Correct 2171 ms 251232 KB Output is correct
31 Correct 2225 ms 253884 KB Output is correct
32 Correct 2375 ms 261648 KB Output is correct
33 Correct 1915 ms 248124 KB Output is correct
34 Correct 2390 ms 253660 KB Output is correct
35 Runtime error 2759 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Halted 0 ms 0 KB -