답안 #93911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93911 2019-01-13T07:04:59 Z brcode The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1979 ms 55096 KB
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
 
using namespace std;
const int MAXN = 2010;
int grid[2010][2010];
int n,m;
int mx;
int ans;
int mn = 1e9;
void revLin(int n, int m) {
	for (int i = 1; i <= n / 2; ++i) {
		for (int j = 1; j <= m; ++j) {
			swap(grid[i][j], grid[n - i + 1][j]); } } }
 
void revCol(int n, int m) {	
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m / 2; ++j) {
			swap(grid[i][j], grid[i][m - j + 1]); } } }
bool find(int mid){
    int temp = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(grid[i][j]<mx-mid){
                temp = max(temp,j);
            }
        }
        for(int j=1;j<=temp;j++){
            if(grid[i][j]>mn+mid){
                return false;
            }
        }
    }
    return true;
}
int check(){
    int l = 0;
    int r = mx-mn;

    while(l<=r){
        int mid = (l+r)/2;
       // cout<<mid<<endl;
        if(find(mid)){
        
            r = mid-1;
        }else{
            l = mid+1;
        }
    }
    return l;
}
int main() {
    cin>>n>>m;
   
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>grid[i][j];
            mx = max(mx,grid[i][j]);
            mn = min(mn,grid[i][j]);
        }
    }
    ans = mx-mn;
    ans = min(check(),ans);
    revLin(n,m);
    ans = min(check(),ans);
    
    revCol(n,m);
 ans = min(check(),ans);
    revLin(n,m);
 ans = min(check(),ans);
    cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 8 ms 1272 KB Output is correct
17 Correct 16 ms 1616 KB Output is correct
18 Correct 16 ms 1528 KB Output is correct
19 Correct 17 ms 1528 KB Output is correct
20 Correct 15 ms 1400 KB Output is correct
21 Correct 21 ms 1656 KB Output is correct
22 Correct 21 ms 1656 KB Output is correct
23 Correct 22 ms 1692 KB Output is correct
24 Correct 20 ms 1528 KB Output is correct
25 Correct 23 ms 1656 KB Output is correct
26 Correct 21 ms 1656 KB Output is correct
27 Correct 21 ms 1656 KB Output is correct
28 Correct 21 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 8 ms 1272 KB Output is correct
17 Correct 16 ms 1616 KB Output is correct
18 Correct 16 ms 1528 KB Output is correct
19 Correct 17 ms 1528 KB Output is correct
20 Correct 15 ms 1400 KB Output is correct
21 Correct 21 ms 1656 KB Output is correct
22 Correct 21 ms 1656 KB Output is correct
23 Correct 22 ms 1692 KB Output is correct
24 Correct 20 ms 1528 KB Output is correct
25 Correct 23 ms 1656 KB Output is correct
26 Correct 21 ms 1656 KB Output is correct
27 Correct 21 ms 1656 KB Output is correct
28 Correct 21 ms 1656 KB Output is correct
29 Correct 1168 ms 37628 KB Output is correct
30 Correct 1170 ms 37796 KB Output is correct
31 Correct 1273 ms 39528 KB Output is correct
32 Correct 1182 ms 39288 KB Output is correct
33 Correct 1072 ms 34272 KB Output is correct
34 Correct 1235 ms 39544 KB Output is correct
35 Correct 1899 ms 55088 KB Output is correct
36 Correct 1658 ms 49940 KB Output is correct
37 Correct 1979 ms 55096 KB Output is correct