답안 #992140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
992140 2024-06-04T02:54:06 Z irmuun The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
2577 ms 102344 KB
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

ll H,W;
ll a[2005][2005],b[2005][2005];

void rotate(){
    for(ll i=1;i<=H;i++){
        for(ll j=1;j<=W;j++){
            b[i][j]=a[i][j];
        }
    }
    for(ll j=1;j<=W;j++){
        for(ll i=H;i>=1;i--){
            a[j][H+1-i]=b[i][j];
        }
    }
    swap(H,W);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>H>>W;
    for(ll i=1;i<=H;i++){
        for(ll j=1;j<=W;j++){
            cin>>a[i][j];
        }
    }
    ll row[2005];
    ll l=0,r=1e9;
    while(l<r){
        ll mid=(l+r)/2;//check
        bool ok=false;
        for(ll z=0;z<4;z++){
            rotate();
            ll val=1e9+5,x,y;
            for(ll i=1;i<=H;i++){
                for(ll j=1;j<=W;j++){
                    if(a[i][j]<val){
                        val=a[i][j];
                        x=i;
                        y=j;
                    }
                }
            }
            for(ll i=1;i<=H;i++){
                row[i]=0;
                for(ll j=1;j<=W;j++){
                    if(a[i][j]<=val+mid){
                        row[i]++;
                    }
                    else break;
                }
            }
            for(ll i=2;i<=H;i++){
                row[i]=min(row[i],row[i-1]);
            }
            ll mn=1e9+5,mx=0;
            for(ll i=1;i<=H;i++){
                for(ll j=row[i]+1;j<=W;j++){
                    mn=min(mn,a[i][j]);
                    mx=max(mx,a[i][j]);
                }
            }
            if(row[x]>=y&&(mx==0||mx-mn<=mid)){
                ok=true;
            }
        }
        if(ok){
            r=mid;
        }
        else{
            l=mid+1;
        }
    }
    cout<<l;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:73:13: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   73 |             if(row[x]>=y&&(mx==0||mx-mn<=mid)){
      |             ^~
joioi.cpp:73:21: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   73 |             if(row[x]>=y&&(mx==0||mx-mn<=mid)){
      |                ~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2532 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2532 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2652 KB Output is correct
15 Correct 2 ms 8536 KB Output is correct
16 Correct 16 ms 8820 KB Output is correct
17 Correct 16 ms 8796 KB Output is correct
18 Correct 15 ms 8796 KB Output is correct
19 Correct 16 ms 9016 KB Output is correct
20 Correct 19 ms 8796 KB Output is correct
21 Correct 22 ms 9132 KB Output is correct
22 Correct 17 ms 9052 KB Output is correct
23 Correct 17 ms 9040 KB Output is correct
24 Correct 15 ms 9088 KB Output is correct
25 Correct 17 ms 9128 KB Output is correct
26 Correct 18 ms 9052 KB Output is correct
27 Correct 20 ms 9052 KB Output is correct
28 Correct 17 ms 9048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2532 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2652 KB Output is correct
15 Correct 2 ms 8536 KB Output is correct
16 Correct 16 ms 8820 KB Output is correct
17 Correct 16 ms 8796 KB Output is correct
18 Correct 15 ms 8796 KB Output is correct
19 Correct 16 ms 9016 KB Output is correct
20 Correct 19 ms 8796 KB Output is correct
21 Correct 22 ms 9132 KB Output is correct
22 Correct 17 ms 9052 KB Output is correct
23 Correct 17 ms 9040 KB Output is correct
24 Correct 15 ms 9088 KB Output is correct
25 Correct 17 ms 9128 KB Output is correct
26 Correct 18 ms 9052 KB Output is correct
27 Correct 20 ms 9052 KB Output is correct
28 Correct 17 ms 9048 KB Output is correct
29 Correct 2419 ms 85348 KB Output is correct
30 Correct 2383 ms 84820 KB Output is correct
31 Correct 2546 ms 86348 KB Output is correct
32 Correct 2533 ms 86204 KB Output is correct
33 Correct 2272 ms 83024 KB Output is correct
34 Correct 2477 ms 86468 KB Output is correct
35 Correct 2577 ms 101972 KB Output is correct
36 Correct 2239 ms 96852 KB Output is correct
37 Correct 2566 ms 102344 KB Output is correct