結果

問題 No.134 走れ!サブロー君
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-10-27 19:58:33
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,478 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 52,736 KB
最終ジャッジ日時 2024-04-27 02:13:45
合計ジャッジ時間 539 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、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, inf));
      |   ^~
main.cpp:40:16: error: ‘vector’ was not declared in this scope
   40 |   dp.resize(n, vector<double>(1<<n, inf));
      |                ^~~~~~
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, inf));
      |                       ^~~~~~
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);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#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, inf));
  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);
        if(dp[i][nmask] == inf) { continue; }
        dp[v][mask] = min(dp[v][mask], 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;
}
0