結果
| 問題 |
No.134 走れ!サブロー君
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-10-27 19:57:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,487 bytes |
| コンパイル時間 | 380 ms |
| コンパイル使用メモリ | 53,320 KB |
| 最終ジャッジ日時 | 2024-11-14 19:21:57 |
| 合計ジャッジ時間 | 779 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:13:1: error: ‘vector’ does not name a type
13 | vector<point> ps;
| ^~~~~~
main.cpp:14:1: error: ‘vector’ does not name a type
14 | 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 ‘int main()’:
main.cpp:34:3: error: ‘ps’ was not declared in this scope
34 | ps.resize(n);
| ^~
main.cpp:40:3: error: ‘dp’ was not declared in this scope
40 | dp.resize(n, vector<double>(1<<n, -1));
| ^~
main.cpp:40:16: error: ‘vector’ was not declared in this scope
40 | 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:40:23: error: expected primary-expression before ‘double’
40 | dp.resize(n, vector<double>(1<<n, -1));
| ^~~~~~
main.cpp:31:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | int x0, y0; scanf("%d%d", &x0, &y0);
| ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:32:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
32 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:37:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
37 | int x, y; double w; scanf("%d%d%lf", &x, &y, &w);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
using i64 = long long;
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);
}
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));
for(int v : range(n)) {
dp[v][1] = dist(ps[v], ps[0]) / calc_speed(1);
}
for(int mask : range(1<<n)) {
for(int v : range(n)) {
for(int i : range(1, n)) {
if(!(mask>>i & 1)) { continue; }
int nmask = mask & ~(1<<i);
double &tmp = dp[v][mask];
if(tmp == -1) { tmp = inf; }
tmp = min(tmp, dp[i][nmask] + dist(ps[v], ps[i]) / calc_speed(mask) + ps[i].w);
}
}
}
double res = dp[0][(1<<n)-1];
printf("%.9lf\n", res);
return 0;
}