結果

問題 No.2675 KUMA
ユーザー XelmephXelmeph
提出日時 2024-03-09 11:37:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 663 ms / 2,000 ms
コード長 3,796 bytes
コンパイル時間 6,936 ms
コンパイル使用メモリ 163,756 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-09 11:38:11
合計ジャッジ時間 7,891 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 3 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 1 ms
6,548 KB
testcase_05 AC 361 ms
6,548 KB
testcase_06 AC 258 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 364 ms
6,548 KB
testcase_09 AC 136 ms
6,548 KB
testcase_10 AC 478 ms
6,548 KB
testcase_11 AC 420 ms
6,548 KB
testcase_12 AC 138 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 7 ms
6,548 KB
testcase_15 AC 1 ms
6,548 KB
testcase_16 AC 663 ms
6,548 KB
testcase_17 AC 2 ms
6,548 KB
testcase_18 AC 1 ms
6,548 KB
testcase_19 AC 2 ms
6,548 KB
testcase_20 AC 1 ms
6,548 KB
testcase_21 AC 2 ms
6,548 KB
testcase_22 AC 2 ms
6,548 KB
testcase_23 AC 1 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 2 ms
6,548 KB
testcase_28 AC 3 ms
6,548 KB
testcase_29 AC 3 ms
6,548 KB
testcase_30 AC 3 ms
6,548 KB
testcase_31 AC 6 ms
6,548 KB
testcase_32 AC 7 ms
6,548 KB
testcase_33 AC 6 ms
6,548 KB
testcase_34 AC 7 ms
6,548 KB
testcase_35 AC 13 ms
6,548 KB
testcase_36 AC 24 ms
6,548 KB
testcase_37 AC 25 ms
6,548 KB
testcase_38 AC 55 ms
6,548 KB
testcase_39 AC 47 ms
6,548 KB
testcase_40 AC 52 ms
6,548 KB
testcase_41 AC 103 ms
6,548 KB
testcase_42 AC 101 ms
6,548 KB
testcase_43 AC 106 ms
6,548 KB
testcase_44 AC 99 ms
6,548 KB
testcase_45 AC 239 ms
6,548 KB
testcase_46 AC 227 ms
6,548 KB
testcase_47 AC 224 ms
6,548 KB
testcase_48 AC 435 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;

namespace utils{
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
    ///----- aliases
    using ll = long long int;
    using ull = unsigned long long;

    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> inline bool CHMIN(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> inline bool CHMAX(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }

    ///----- tuple I/O
    template <class S, class T>
    istream& operator>>(istream& is, tuple<S, T>& t){
        return is >> get<0>(t) >> get<1>(t);
    }

    template<class T>
    istream& operator>>(istream& is, vector<T>& v){
        for (auto &&x : v) { is >> x; } return is;
    }

    ///----- constants
    constexpr ll INFLL   = 1'000'000'000'000'000'020ll;
    constexpr int INF     = 1'000'000'009;
    constexpr double PI      = 3.14'159'265'358'979'323'846;
    constexpr double EPS     = 1e-12;
}
using namespace utils;


class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    int N;
    vector<tuple<int, int>> xy;

    bool input() {
        is >> N;
        xy.resize(N);
        is >> xy;
        return !!is;
    }

    void run();
};
using Coord = tuple<int,int>;

Coord operator+(const Coord& a, const Coord& b){
    return {get<0>(a) + get<0>(b), get<1>(a) + get<1>(b)};
}

void solver::run(){
    if(!input()) return;
    set<Coord> V;
    map<Coord, int> UMA;
    vector<tuple<Coord, Coord>> kma(4);
    // EWSN
    kma[0] = {{2, -1}, {2, 1}};
    kma[1] = {{-2, -1}, {-2, 1}};
    kma[2] = {{-1, -2}, {1, -2}};
    kma[3] = {{-1, 2}, {1, 2}};

    for (int i = 0; i < N; ++i) {
        auto&& xyi = xy[i];
        V.emplace(xyi);
        UMA.emplace(xyi, i);
        for (auto &&[ka,kb]: kma) {
            V.insert(xyi + ka);
            V.insert(xyi + kb);
        } // end [kx,ky]
    } // end i

    vector<int> minK(1<<N, INF);
    minK[0] = 0;
    for (auto &&p: V) {
        if(UMA.count(p)) continue;
        vector<int> upd = minK;

        for (int i = 0; i < upd.size(); ++i) {
            for (auto &&km:kma) {
                unsigned sp = 0;
                auto [a,b] = km;
                if(UMA.count(p + a)){ sp |= 1u << UMA[p + a]; }
                if(UMA.count(p + b)){ sp |= 1u << UMA[p + b]; }
                CHMIN(upd[i|sp], minK[i] + 1);
            } // end km
        } // end i
        minK = std::move(upd);
    } // end p

    if(minK.back() == INF){
        os << "-1\n";
    }
    else os << minK.back() << '\n';
}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef XELMH
    string test_cases = "test_e.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}
0