結果

問題 No.2612 Close the Distance
ユーザー RubikunRubikun
提出日時 2024-01-19 22:01:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,138 ms / 3,000 ms
コード長 2,549 bytes
コンパイル時間 2,563 ms
コンパイル使用メモリ 214,472 KB
実行使用メモリ 26,428 KB
最終ジャッジ日時 2024-01-20 00:17:41
合計ジャッジ時間 21,198 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 859 ms
26,420 KB
testcase_07 AC 738 ms
26,424 KB
testcase_08 AC 703 ms
26,424 KB
testcase_09 AC 803 ms
26,424 KB
testcase_10 AC 745 ms
26,424 KB
testcase_11 AC 847 ms
26,424 KB
testcase_12 AC 786 ms
26,424 KB
testcase_13 AC 845 ms
26,424 KB
testcase_14 AC 815 ms
26,428 KB
testcase_15 AC 831 ms
26,424 KB
testcase_16 AC 931 ms
21,764 KB
testcase_17 AC 1,076 ms
21,764 KB
testcase_18 AC 1,057 ms
21,764 KB
testcase_19 AC 1,130 ms
21,764 KB
testcase_20 AC 768 ms
21,764 KB
testcase_21 AC 1,023 ms
21,764 KB
testcase_22 AC 666 ms
21,764 KB
testcase_23 AC 756 ms
21,764 KB
testcase_24 AC 845 ms
21,764 KB
testcase_25 AC 1,138 ms
21,764 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://atcoder.jp/contests/xmascon19/tasks/xmascon19_f

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005;
const ll INF=1LL<<34;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<pair<ll,ll>> S(N);
    for(int i=0;i<N;i++){
        ll a,b;cin>>a>>b;
        S[i]=mp(a+b,a-b);
    }
    sort(all(S));
    
    auto solve=[&](vector<pair<ll,ll>> X,int type,ll len){
        if(si(X)==0) return X;
        ll miH=INF,maH=-INF,miW=INF,maW=-INF;
        for(auto [a,b]:X){
            chmin(miH,a);
            chmax(maH,a);
            chmin(miW,b);
            chmax(maW,b);
        }
        vector<pair<ll,ll>> res;
        ll U,D,L,R;
        if(type==0){
            U=miH;
            D=miH+len;
            L=miW;
            R=miW+len;
        }
        if(type==1){
            U=miH;
            D=miH+len;
            L=maW-len;
            R=maW;
        }
        if(type==2){
            U=maH-len;
            D=maH;
            L=miW;
            R=miW+len;
        }
        if(type==3){
            U=maH-len;
            D=maH;
            L=maW-len;
            R=maW;
        }
        for(auto [a,b]:X){
            if(U<=a&&a<=D&&L<=b&&b<=R){
                
            }else{
                res.push_back(mp(a,b));
            }
        }
        return res;
    };
    
    ll left=-1,right=1LL<<33;
    while(right-left>1){
        ll mid=(left+right)/2;
        bool f=false;
        for(int a=0;a<4;a++){
            auto T1=S;
            auto T2=solve(T1,a,mid);
            if(si(T1)==si(T2)) continue;
            if(si(T2)==0) f=true;
            for(int b=0;b<4;b++){
                auto T3=solve(T2,b,mid);
                if(si(T2)==si(T3)) continue;
                if(si(T3)==0) f=true;
                for(int c=0;c<4;c++){
                    auto T4=solve(T3,c,mid);
                    if(si(T4)==0) f=true;
                    if(f) break;
                }
                if(f) break;
            }
            if(f) break;
        }
        if(f) right=mid;
        else left=mid;
    }
    
    cout<<right<<endl;
}

0