답안 #537062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537062 2022-03-14T10:58:00 Z qwerasdfzxcl The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
2947 ms 31852 KB
    #include <bits/stdc++.h>
    using namespace std;
     
    int n, m, mn = 1e9, a[2010][2010], b[2010][2010];
     
    void rot(){
    	for(int i = 1; i <= n; i++){
    		for(int j = 1; j <= m; j++){
    			b[j][n + 1 - i] = a[i][j];
    		}
    	}
    	swap(n, m);
    	for(int i = 1; i <= n; i++){
    		for(int j = 1; j <= m; j++){
    			a[i][j] = b[i][j];
    		}
    	}
    }
     
    int can(int k){
    	for(int dum = 0; dum < 4; dum++){
    		int lst = m, omx = 0, omn = 1e9;
    		for(int i = 1; i <= n; i++){
    			for(int j = 1; j <= lst; j++){
    				if(a[i][j] > mn + k){ lst = j - 1; break; }
    			}
    			for(int j = lst + 1; j <= m; j++){
    				omx = max(omx, a[i][j]);
    				omn = min(omn, a[i][j]);
                    if(omx - omn > k) break;
    			}
                if(omx - omn > k) break;
    		}
    		if(omx - omn <= k) return 1;
    		if(dum < 3) rot();
    	}
    	return 0;
    }
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cin >> n >> m;
    	for(int i = 1; i <= n; i++){
    		for(int j = 1; j <= m; j++){
    			cin >> a[i][j];
                mn = min(mn, a[i][j]);
    		}
    	}
    	int s = 0, e = 1e9;
    	while(s <= e){
    		int mid = (s + e) / 2;
    		if(can(mid)) e = mid - 1;
    		else s = mid + 1;
    	}
    cout << s << '\n';
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 6 ms 2132 KB Output is correct
17 Correct 6 ms 2132 KB Output is correct
18 Correct 6 ms 2140 KB Output is correct
19 Correct 6 ms 2132 KB Output is correct
20 Correct 9 ms 2132 KB Output is correct
21 Correct 9 ms 2132 KB Output is correct
22 Correct 13 ms 2132 KB Output is correct
23 Correct 9 ms 2164 KB Output is correct
24 Correct 7 ms 2132 KB Output is correct
25 Correct 11 ms 2236 KB Output is correct
26 Correct 8 ms 2160 KB Output is correct
27 Correct 9 ms 2200 KB Output is correct
28 Correct 8 ms 2240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 6 ms 2132 KB Output is correct
17 Correct 6 ms 2132 KB Output is correct
18 Correct 6 ms 2140 KB Output is correct
19 Correct 6 ms 2132 KB Output is correct
20 Correct 9 ms 2132 KB Output is correct
21 Correct 9 ms 2132 KB Output is correct
22 Correct 13 ms 2132 KB Output is correct
23 Correct 9 ms 2164 KB Output is correct
24 Correct 7 ms 2132 KB Output is correct
25 Correct 11 ms 2236 KB Output is correct
26 Correct 8 ms 2160 KB Output is correct
27 Correct 9 ms 2200 KB Output is correct
28 Correct 8 ms 2240 KB Output is correct
29 Correct 1889 ms 31776 KB Output is correct
30 Correct 1679 ms 31776 KB Output is correct
31 Correct 1587 ms 31764 KB Output is correct
32 Correct 1421 ms 31784 KB Output is correct
33 Correct 1556 ms 31596 KB Output is correct
34 Correct 1599 ms 31824 KB Output is correct
35 Correct 2947 ms 31824 KB Output is correct
36 Correct 2062 ms 31592 KB Output is correct
37 Correct 2822 ms 31852 KB Output is correct