結果
| 問題 |
No.134 走れ!サブロー君
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-10-27 18:18:28 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,585 bytes |
| コンパイル時間 | 604 ms |
| コンパイル使用メモリ | 51,580 KB |
| 最終ジャッジ日時 | 2024-11-14 19:21:54 |
| 合計ジャッジ時間 | 1,251 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:12:1: error: ‘vector’ does not name a type
12 | vector<point> ps;
| ^~~~~~
main.cpp:13:1: error: ‘vector’ does not name a type
13 | vector<vector<double>> dp;
| ^~~~~~
main.cpp: In function ‘double calc_speed(int)’:
main.cpp:20:17: error: ‘ps’ was not declared in this scope
20 | weight += ps[i].w;
| ^~
main.cpp: In function ‘double rec(int, int)’:
main.cpp:31:17: error: ‘dp’ was not declared in this scope
31 | double &res = dp[v][mask];
| ^~
main.cpp:35:37: error: ‘ps’ was not declared in this scope
35 | if(mask == 1) { return res = dist(ps[v], ps[0]) / speed; }
| ^~
main.cpp:41:41: error: ‘ps’ was not declared in this scope
41 | res = min(res, rec(nmask, i) + dist(ps[v], ps[i]) / speed + ps[i].w);
| ^~
main.cpp: In function ‘int main()’:
main.cpp:50:3: error: ‘ps’ was not declared in this scope
50 | ps.resize(n);
| ^~
main.cpp:56:3: error: ‘dp’ was not declared in this scope
56 | dp.resize(n, vector<double>(1<<n, -1));
| ^~
main.cpp:56:16: error: ‘vector’ was not declared in this scope
56 | dp.resize(n, vector<double>(1<<n, -1));
| ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
2 | #include <algorithm>
+++ |+#include <vector>
3 | using namespace std;
main.cpp:56:23: error: expected primary-expression before ‘double’
56 | dp.resize(n, vector<double>(1<<n, -1));
| ^~~~~~
main.cpp:47:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
47 | int x0, y0; scanf("%d%d", &x0, &y0);
| ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:48:8: warning: ignoring return value of ‘int
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};
struct point { int x, y; double w; };
const int inf = 987654321;
int n;
vector<point> ps;
vector<vector<double>> dp;
double calc_speed(int mask) {
double weight = 0;
for(int i : range(n)) {
// 荷物がある = ビットが立っている
if(mask>>i & 1) {
weight += ps[i].w;
}
}
return 120. / (weight + 100);
}
int dist(point p, point q) {
return abs(p.x - q.x) + abs(p.y - q.y);
}
double rec(int mask, int v) {
double &res = dp[v][mask];
if(res != -1) { return res; }
double speed = calc_speed(mask);
// v番目から酒屋に帰る
if(mask == 1) { return res = dist(ps[v], ps[0]) / speed; }
res = inf;
// v番目からi番目の配達先に行って荷物を降ろす
for(int i : range(1, n)) {
if(!(mask>>i & 1)) { continue; }
int nmask = mask & ~(1<<i);
res = min(res, rec(nmask, i) + dist(ps[v], ps[i]) / speed + ps[i].w);
}
return res;
}
int main(void) {
int x0, y0; scanf("%d%d", &x0, &y0);
scanf("%d", &n);
n += 1;
ps.resize(n);
ps[0] = point({x0, y0, 0.});
for(int i : range(1, n)) {
int x, y; double w; scanf("%d%d%lf", &x, &y, &w);
ps[i] = point({x, y, w});
}
dp.resize(n, vector<double>(1<<n, -1));
double res = rec((1<<n)-1, 0);
printf("%.9lf\n", res);
return 0;
}