結果

問題 No.2675 KUMA
ユーザー てんぷらてんぷら
提出日時 2024-03-15 22:14:05
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,848 bytes
コンパイル時間 5,785 ms
コンパイル使用メモリ 309,304 KB
実行使用メモリ 7,884 KB
最終ジャッジ日時 2024-03-15 22:14:13
合計ジャッジ時間 7,804 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,296 KB
testcase_01 AC 19 ms
7,296 KB
testcase_02 AC 19 ms
7,296 KB
testcase_03 AC 18 ms
7,296 KB
testcase_04 AC 18 ms
7,296 KB
testcase_05 AC 27 ms
7,884 KB
testcase_06 AC 26 ms
7,884 KB
testcase_07 AC 18 ms
7,296 KB
testcase_08 AC 29 ms
7,884 KB
testcase_09 AC 23 ms
7,552 KB
testcase_10 AC 29 ms
7,884 KB
testcase_11 AC 29 ms
7,884 KB
testcase_12 AC 22 ms
7,424 KB
testcase_13 AC 18 ms
7,296 KB
testcase_14 AC 19 ms
7,296 KB
testcase_15 AC 18 ms
7,296 KB
testcase_16 AC 34 ms
7,884 KB
testcase_17 AC 19 ms
7,296 KB
testcase_18 AC 18 ms
7,296 KB
testcase_19 AC 18 ms
7,296 KB
testcase_20 AC 18 ms
7,296 KB
testcase_21 AC 18 ms
7,296 KB
testcase_22 AC 18 ms
7,296 KB
testcase_23 AC 18 ms
7,296 KB
testcase_24 AC 18 ms
7,296 KB
testcase_25 AC 19 ms
7,296 KB
testcase_26 AC 18 ms
7,296 KB
testcase_27 AC 18 ms
7,296 KB
testcase_28 AC 18 ms
7,296 KB
testcase_29 AC 18 ms
7,296 KB
testcase_30 AC 18 ms
7,296 KB
testcase_31 AC 18 ms
7,296 KB
testcase_32 AC 18 ms
7,296 KB
testcase_33 AC 18 ms
7,296 KB
testcase_34 AC 19 ms
7,296 KB
testcase_35 AC 19 ms
7,296 KB
testcase_36 AC 19 ms
7,296 KB
testcase_37 AC 19 ms
7,296 KB
testcase_38 AC 20 ms
7,424 KB
testcase_39 AC 20 ms
7,424 KB
testcase_40 AC 20 ms
7,424 KB
testcase_41 AC 21 ms
7,424 KB
testcase_42 AC 21 ms
7,424 KB
testcase_43 AC 22 ms
7,424 KB
testcase_44 AC 21 ms
7,424 KB
testcase_45 AC 25 ms
7,552 KB
testcase_46 AC 25 ms
7,552 KB
testcase_47 AC 24 ms
7,552 KB
testcase_48 AC 30 ms
7,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
using namespace std;
using namespace atcoder;
using mint = modint998244353;
const int inf = 1000000007;
const ll longinf = 1ll << 60;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector a(1001, vector(1001, 0));
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        a[x][y] = 1 << i;
    }
    int all = 1 << n;
    vector<int> dp(all, inf);
    dp[0] = 0;
    auto get = [&](int x, int y) {
        if(0 <= x && x <= 1000 && 0 <= y && y <= 1000) {
            return a[x][y];
        } else {
            return 0;
        }
    };
    REP(x, -2, 1003)
    REP(y, -2, 1003) {
        if(get(x, y) > 0) {
            continue;
        }
        vector<int> vals;
        {
            int u = get(x + 2, y + 1) | get(x + 2, y - 1);
            if(u > 0)
                vals.push_back(u);
        }
        {
            int u = get(x - 2, y + 1) | get(x - 2, y - 1);
            if(u > 0)
                vals.push_back(u);
        }
        {
            int u = get(x + 1, y + 2) | get(x - 1, y + 2);
            if(u > 0)
                vals.push_back(u);
        }
        {
            int u = get(x + 1, y - 2) | get(x - 1, y - 2);
            if(u > 0)
                vals.push_back(u);
        }
        if(vals.size() > 0) {
            vector<int> ndp = dp;
            rep(i, all) for(auto v : vals) {
                ndp[i | v] = min(ndp[i | v], dp[i] + 1);
            }
            dp.swap(ndp);
        }
    }
    if(dp[all - 1] == inf) {
        cout << -1 << endl;
    } else {
        cout << dp[all - 1] << endl;
    }
    return 0;
}
0