結果

問題 No.2955 Pizza Delivery Plan
ユーザー anago-pie
提出日時 2025-02-07 15:40:06
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 5,808 bytes
コンパイル時間 3,598 ms
コンパイル使用メモリ 305,248 KB
実行使用メモリ 219,796 KB
最終ジャッジ日時 2025-02-07 15:41:21
合計ジャッジ時間 51,801 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 TLE * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define debug 0
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int MOD = 1000000007;
const double pi = atan2(0, -1);
const int inf = 1 << 31 - 1;
const ll INF = 1LL << 63 - 1;
#include <time.h>
#include <chrono>
//vector
template<typename T>
void printv(vector<T> v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i];
if (i < v.size() - 1) {
cout << " ";
}
}
cout << endl;
}
//vector
template<typename T>
void print1(vector<T> v) {
for (auto x : v) {
cout << x << endl;
}
}
//
template<typename T>
void printvv(vector<vector<T>> vv) {
for (vector<T> v : vv) {
printv(v);
}
}
//vector
template<typename T>
void rsort(vector<T>& v) {
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
}
//priority_queue
template<typename T>
struct rpriority_queue {
priority_queue<T, vector<T>, greater<T>> pq;
void push(T x) {
pq.push(x);
}
void pop() {
pq.pop();
}
T top() {
return pq.top();
}
size_t size() {
return pq.size();
}
bool empty() {
return pq.empty();
}
};
//mod mod
//a^n(mod ver.)
ll power(ll a, ll n) {
if (n == 0) {
return 1;
}
else if (n % 2 == 0) {
ll x = power(a, n / 2);
x *= x;
x %= mod;
return x;
}
else {
ll x = power(a, n - 1);
x *= a;
x %= mod;
return x;
}
}
//
ll modinv(ll p) {
return power(p, mod - 2) % mod;
}
//Mex
struct Mex {
map<int, int> mp;
set<int> s;
Mex(int Max) {
for (int i = 0; i <= Max; i++) {
s.insert(i);
}
}
int _mex = 0;
void Input(int x) {
mp[x]++;
s.erase(x);
if (_mex == x) {
_mex = *begin(s);
}
}
void Remove(int x) {
if (mp[x] == 0) {
cout << "Mex ERROR!: NO VALUE WILL BE REMOVED" << endl;
}
mp[x]--;
if (mp[x] == 0) {
s.insert(x);
if (*begin(s) == x) {
_mex = x;
}
}
}
int mex() {
return _mex;
}
};
//Yes/No
void YN(bool true_or_false) {
cout << (true_or_false ? "Yes" : "No") << endl;
}
//Union-Find
struct UnionFind {
vector<int> par;
UnionFind(int N) : par(N) {
for (int i = 0; i < N; i++) {
par[i] = -1;
}
}
//root(x):x
int root(int x) {
if (par[x] == -1) {
return x;
}
else {
return par[x] = root(par[x]);
}
}
//isSame(x,y):xytrue
bool isSame(int x, int y) {
if (root(x) == root(y)) {
return true;
}
else {
return false;
}
}
//Union(x,y):xy
void Union(int x, int y) {
int X = root(x);
int Y = root(y);
if (X == Y) {
return;
}
if (X < Y) {
swap(X, Y);
}
par[X] = Y;
}
};
//(
ll gcd(ll a, ll b) {
if (b > a) {
swap(a, b);
}
while (a % b != 0) {
ll t = a;
a = b;
b = t % b;
}
return b;
}
//gcd
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
ll x = (a / g) * b;
return x;
}
struct SegTree {
vector<int> tree;
vector<int> lazy;
int n = 1;
SegTree(int N, int H) {
while (n < N) {
n *= 2;
}
vector<int> v(n * 2, H + 1);
swap(tree, v);
vector<int> u(n * 2, 200005);
swap(lazy, u);
}
void update(int val, int l, int r, int u, int t, int now) {
if (l >= t || r <= u) {
return;
}
else if (l <= u && r >= t) {
lazy[now] = min(lazy[now], val);
}
else {
tree[now] = min(tree[now], val);
update(val, l, r, u, (u + t) / 2, now * 2 + 1);
update(val, l, r, (u + t) / 2, t, now * 2 + 2);
}
}
void treeup(int now, int val) {
if (tree[now] > val) {
tree[now] = val;
if (now > 0) {
treeup((now - 1) / 2, val);
}
}
}
int Min(int l, int r, int u, int t, int now) {
if (l >= t || r <= u) {
return inf;
}
else if (l <= u && r >= t) {
treeup(now, lazy[now]);
return tree[now];
}
else {
treeup(now, lazy[now]);
lazy[now * 2 + 1] = min(lazy[now * 2 + 1], lazy[now]);
lazy[now * 2 + 2] = min(lazy[now * 2 + 2], lazy[now]);
return min(Min(l, r, u, (u + t) / 2, now * 2 + 1), Min(l, r, (u + t) / 2, t, now * 2 + 2));
}
}
int query(int l, int r) {
return Min(l, r, 0, n, 0);
}
};
ld dist(vector<ld> x, vector<ld> y) {
ld d = sqrt((x[0] - y[0]) * (x[0] - y[0]) + (x[1] - y[1]) * (x[1] - y[1]));
return d;
}
int main() {
int N, K;
cin >> N >> K;
vector<vector<ld>> plot(N+1, vector<ld>(2));
plot[0] = { 0,0 };
rep(i, N) {
cin >> plot[i+1][0] >> plot[i+1][1];
}
vector<vector<vector<ld>>> record(pow(2, N+1), vector<vector<ld>>(N + 1, vector<ld>(K + 1, INF)));
record[0][0][K] = 0;
rpriority_queue < tuple<ld, ll,int, int>> pq;
pq.push({ 0,0,K,0 });
while (!pq.empty()) {
auto t = pq.top();
pq.pop();
ld now_score;
bitset<15> b;
int now;
int k;
tie(now_score, b,k, now) = t;
if (k > 0) {
for (int x = 1; x <= N; x++) {
if (!b[x]) {
b[x] = 1;
ld d = dist(plot[now], plot[x]);
if (record[b.to_ullong()][x][k-1]>now_score+d) {
record[b.to_ullong()][x][k-1] = now_score + d;
pq.push({ now_score + d, b.to_ullong(), k - 1,x });
}
b[x] = 0;
}
}
}
if (now!=0 && record[b.to_ullong()][0][K] > now_score + dist(plot[0], plot[now])) {
record[b.to_ullong()][0][K] = now_score + dist(plot[0], plot[now]);
pq.push({ now_score + dist(plot[0],plot[now]), b.to_ullong(), K, 0 });
}
}
bitset<15> b = 0;
for (int i = 1; i <= N; i++) {
b[i] = 1;
}
cout << setprecision(10) << fixed;
cout << record[b.to_ullong()][0][K] << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0