結果

問題 No.2675 KUMA
ユーザー じなぺじなぺ
提出日時 2024-03-18 19:33:13
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 461 ms / 2,000 ms
コード長 2,269 bytes
コンパイル時間 3,200 ms
コンパイル使用メモリ 261,880 KB
実行使用メモリ 36,992 KB
最終ジャッジ日時 2024-03-18 19:33:22
合計ジャッジ時間 7,771 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 138 ms
19,328 KB
testcase_06 AC 115 ms
15,232 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 150 ms
21,120 KB
testcase_09 AC 45 ms
9,984 KB
testcase_10 AC 461 ms
23,552 KB
testcase_11 AC 409 ms
22,016 KB
testcase_12 AC 27 ms
10,624 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 117 ms
36,992 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 3 ms
6,676 KB
testcase_32 AC 4 ms
6,676 KB
testcase_33 AC 5 ms
6,676 KB
testcase_34 AC 3 ms
6,676 KB
testcase_35 AC 6 ms
6,676 KB
testcase_36 AC 14 ms
6,676 KB
testcase_37 AC 13 ms
6,676 KB
testcase_38 AC 22 ms
6,676 KB
testcase_39 AC 18 ms
6,676 KB
testcase_40 AC 26 ms
6,676 KB
testcase_41 AC 41 ms
8,320 KB
testcase_42 AC 43 ms
8,320 KB
testcase_43 AC 38 ms
8,448 KB
testcase_44 AC 43 ms
8,064 KB
testcase_45 AC 84 ms
14,848 KB
testcase_46 AC 89 ms
14,592 KB
testcase_47 AC 82 ms
14,208 KB
testcase_48 AC 164 ms
22,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint998244353;

//多倍長整数//
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//using Bint = mp::cpp_int;

const int INF = 1e9;
const int MOD = 998244353;
const long long LINF = 4e18;

using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vvvvi = vector<vector<vector<vector<int>>>>;
using vvl = vector<vector<long long>>;
using vvvl = vector<vector<vector<long long>>>;
using vvvvl = vector<vector<vector<vector<long long>>>>;
using vvc = vector<vector<char>>;
using vvb = vector<vector<bool>>;
using vvvb = vector<vector<vector<bool>>>;
using vvvvb = vector<vector<vector<vector<bool>>>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ALL(obj) (obj).begin(),(obj).end()

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vi x(n),y(n);
	rep(i,n) cin >> x[i] >> y[i];
	vvi dx = {{-1,1},{2,2},{1,-1},{-2,-2}};
	vvi dy = {{2,2},{1,-1},{-2,-2},{-1,1}};
	vector<pair<int,int>> s;
	vi da = {-1,1,2,2,1,-1,-2,-2};
	vi db = {2,2,1,-1,-2,-2,-1,1};
	rep(i,n){
		rep(j,8){
			bool ok = true;
			rep(k,n) if(x[i] + da[j] == x[k] && y[i] + db[j] == y[k]) ok = false;
			if(ok) s.push_back({x[i] + da[j],y[i] + db[j]});
		}
	}
	sort(ALL(s));
	s.erase(unique(ALL(s)),s.end());
	//rep(i,s.size()) cout << s[i].first << ' ' << s[i].second << endl;
	vvi dp(s.size() + 1,vi(1<<n,INF));
	dp[0][0] = 0;
	rep(i,s.size()){
		rep(j,(1<<n)){
			if(dp[i][j] == INF) continue;
			dp[i + 1][j] = min(dp[i + 1][j],dp[i][j]);
			rep(k,4){
				int bit = j;
				rep(l,n){
					rep(m,2){
						if(s[i].first + dx[k][m] == x[l] && s[i].second + dy[k][m] == y[l]) bit = (bit | (1<<l));
					}
				}
				//cout << bit << endl;
				dp[i + 1][bit] = min(dp[i + 1][bit],dp[i][j] + 1);
			}
		}
	}
	if(dp[s.size()][(1<<n) - 1] == INF) cout << -1 << endl;
	else cout << dp[s.size()][(1<<n) - 1] << endl;
	return 0;
}
0