답안 #991905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
991905 2024-06-03T11:14:14 Z imarn The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
533 ms 54868 KB
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
int a[2005][2005]{0},mx=0,mn=1e9,h,w;
bool ch(ll x){
    int id=w+1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(mx-a[i][j]>x)id=min(id,j);
        }
        for(int j=id;j<=w;j++){
            if(a[i][j]-mn>x)return 0;
        }
    }return 1;
}
ll solve(){
    ll l=0,r=mx-mn;
    while(l<r){
        ll m=(l+r)>>1;
        if(ch(m))r=m;
        else l=m+1;
    }return l;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>h>>w;
    for(int i=1;i<=h;i++)for(int j=1;j<=w;j++)cin>>a[i][j],mx=max(mx,a[i][j]),mn=min(mn,a[i][j]);
    ll ans=1e9;
    ans=min(solve(),ans);
    for(int i=1;i<=h;i++)for(int j=1;j<=w/2;j++)swap(a[i][j],a[i][w-j+1]);
    ans=min(solve(),ans);
    for(int j=1;j<=w;j++)for(int i=1;i<=h/2;i++)swap(a[i][j],a[h-i+1][j]);
    ans=min(solve(),ans);
    for(int i=1;i<=h;i++)for(int j=1;j<=w/2;j++)swap(a[i][j],a[i][w-j+1]);
    ans=min(solve(),ans);
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 4 ms 2900 KB Output is correct
18 Correct 4 ms 2652 KB Output is correct
19 Correct 4 ms 2652 KB Output is correct
20 Correct 4 ms 2652 KB Output is correct
21 Correct 5 ms 2908 KB Output is correct
22 Correct 6 ms 2908 KB Output is correct
23 Correct 6 ms 3000 KB Output is correct
24 Correct 5 ms 2980 KB Output is correct
25 Correct 7 ms 3012 KB Output is correct
26 Correct 6 ms 3016 KB Output is correct
27 Correct 5 ms 2780 KB Output is correct
28 Correct 5 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 4 ms 2900 KB Output is correct
18 Correct 4 ms 2652 KB Output is correct
19 Correct 4 ms 2652 KB Output is correct
20 Correct 4 ms 2652 KB Output is correct
21 Correct 5 ms 2908 KB Output is correct
22 Correct 6 ms 2908 KB Output is correct
23 Correct 6 ms 3000 KB Output is correct
24 Correct 5 ms 2980 KB Output is correct
25 Correct 7 ms 3012 KB Output is correct
26 Correct 6 ms 3016 KB Output is correct
27 Correct 5 ms 2780 KB Output is correct
28 Correct 5 ms 2908 KB Output is correct
29 Correct 255 ms 37464 KB Output is correct
30 Correct 256 ms 37600 KB Output is correct
31 Correct 329 ms 39060 KB Output is correct
32 Correct 241 ms 38992 KB Output is correct
33 Correct 217 ms 34900 KB Output is correct
34 Correct 285 ms 39288 KB Output is correct
35 Correct 462 ms 54868 KB Output is correct
36 Correct 383 ms 49748 KB Output is correct
37 Correct 533 ms 54868 KB Output is correct