結果
問題 | No.2675 KUMA |
ユーザー |
👑 |
提出日時 | 2024-03-15 23:23:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 96 ms / 2,000 ms |
コード長 | 2,389 bytes |
コンパイル時間 | 4,554 ms |
コンパイル使用メモリ | 265,840 KB |
最終ジャッジ日時 | 2025-02-20 06:06:52 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 47 |
ソースコード
#include<bits/stdc++.h>#include<atcoder/all>#define rep(i,n) for(int i=0;i<n;i++)using namespace std;using namespace atcoder;typedef long long ll;typedef vector<int> vi;typedef vector<long long> vl;typedef vector<vector<int>> vvi;typedef vector<vector<long long>> vvl;typedef long double ld;typedef pair<int, int> P;ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;}template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;}template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); returnos;}template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : "");return os;}template<typename T> void chmin(T& a, T b){a = min(a, b);}template<typename T> void chmax(T& a, T b){a = max(a, b);}int main(){int n;cin >> n;vector<int> x(n), y(n);rep(i, n) cin >> x[i] >> y[i];map<pair<int, int>, vector<vector<int>>> ma;vector<tuple<int, int, int>> v = {{0, 2, 1}, {0, 2, -1}, {1, 1, 2}, {1, -1, 2}, {2, -2, 1}, {2, -2, -1}, {3, 1, -2}, {3, -1, -2}};rep(i, n){for(auto [dir, dy, dx] : v){pair<int, int> p = {y[i] + dy, x[i] + dx};if(ma.find(p) == ma.end()) ma[p].resize(4);ma[p][dir].push_back(i);}}{vector<pair<int, int>> del;rep(i, n){pair<int, int> p = {y[i], x[i]};if(ma.find(p) == ma.end()) continue;del.push_back(p);}for(auto p : del) ma.erase(p);}const int INF = 1001001;vector<int> dp(1 << n, INF);dp[0] = 0;for(auto& [p, vec] : ma){vector<int> dp_old(1 << n, INF);swap(dp, dp_old);rep(bit, 1 << n){rep(dir, 4){int bit_new = bit;for(auto idx : vec[dir]) bit_new |= (1 << idx);chmin(dp[bit_new], dp_old[bit] + 1);chmin(dp[bit], dp_old[bit]);}}}int ans = dp[(1 << n) -1];if(ans >= INF) cout << "-1\n";else cout << ans << "\n";return 0;}