結果

問題 No.2675 KUMA
ユーザー 👑 hos.lyrichos.lyric
提出日時 2024-03-15 22:00:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,681 bytes
コンパイル時間 1,226 ms
コンパイル使用メモリ 123,544 KB
実行使用メモリ 13,480 KB
最終ジャッジ日時 2024-03-15 22:00:23
合計ジャッジ時間 5,035 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 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 1 ms
6,676 KB
testcase_05 AC 6 ms
6,676 KB
testcase_06 AC 6 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 7 ms
6,676 KB
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 7 ms
6,676 KB
testcase_11 AC 7 ms
6,676 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


constexpr int DX[4] = {+1, 0, -1, 0};
constexpr int DY[4] = {0, +1, 0, -1};
constexpr int INF = 1001001001;

int N;
vector<int> X, Y;

int U;
map<pair<int, int>, int> ids;
int get(int x, int y) {
  const pair<int, int> key(x, y);
  auto it = ids.find(key);
  if (it != ids.end()) {
    return it->second;
  } else {
    return ids[key] = U++;
  }
}

int main() {
  for (; ~scanf("%d", &N); ) {
    X.resize(N);
    Y.resize(N);
    for (int u = 0; u < N; ++u) {
      scanf("%d%d", &X[u], &Y[u]);
    }
    
    U = 0;
    ids.clear();
    for (int u = 0; u < N; ++u) {
      ids[make_pair(X[u], Y[u])] = -1;
    }
    
    int qss[110][4] = {};
    for (int u = 0; u < N; ++u) {
      for (int h = 0; h < 4; ++h) {
        for (const int dh : {+1, -1}) {
          const int hh = (h + dh) & 3;
          const int a = get(X[u] + 2 * DX[h] + DX[hh], Y[u] + 2 * DY[h] + DY[hh]);
          if (~a) {
// cerr<<u<<" "<<h<<": "<<a<<endl;
            qss[a][h] |= 1 << u;
          }
        }
      }
    }
    
    vector<int> crt(1 << N, INF);
    crt[0] = 0;
    for (int a = 0; a < U; ++a) {
      vector<int> nxt = crt;
      for (int h = 0; h < 4; ++h) {
        const int q = qss[a][h];
        if (q) {
          for (int p = q; p < 1 << N; ++p |= q) {
            chmin(nxt[p], crt[p - q] + 1);
          }
        }
      }
      crt.swap(nxt);
    }
    const int ans = crt.back();
    printf("%d\n", (ans < INF) ? ans : -1);
  }
  return 0;
}
0