結果

問題 No.1413 Dynamic Sushi
ユーザー tnakao0123tnakao0123
提出日時 2021-03-03 23:26:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 493 ms / 4,000 ms
コード長 3,276 bytes
コンパイル時間 1,000 ms
コンパイル使用メモリ 99,184 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 15:05:42
合計ジャッジ時間 11,835 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 437 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 445 ms
6,940 KB
testcase_05 AC 456 ms
6,940 KB
testcase_06 AC 463 ms
6,940 KB
testcase_07 AC 472 ms
6,944 KB
testcase_08 AC 459 ms
6,940 KB
testcase_09 AC 487 ms
6,944 KB
testcase_10 AC 466 ms
6,944 KB
testcase_11 AC 470 ms
6,944 KB
testcase_12 AC 483 ms
6,940 KB
testcase_13 AC 484 ms
6,944 KB
testcase_14 AC 489 ms
6,940 KB
testcase_15 AC 483 ms
6,944 KB
testcase_16 AC 479 ms
6,944 KB
testcase_17 AC 486 ms
6,944 KB
testcase_18 AC 493 ms
6,940 KB
testcase_19 AC 476 ms
6,940 KB
testcase_20 AC 206 ms
6,940 KB
testcase_21 AC 4 ms
6,940 KB
testcase_22 AC 467 ms
6,940 KB
testcase_23 AC 477 ms
6,940 KB
testcase_24 AC 479 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1413.cc:  No.1413 Dynamic Sushi - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 12;
const int NBITS = 1 << MAX_N;
const double PI = acos(-1.0);
const int CNT = 50;
const double DINF = 1e60;

/* typedef */

template <typename T>
struct Pt {
  T x, y;
  Pt() {}
  Pt(T _x, T _y) : x(_x), y(_y) {}
  Pt(const Pt<T> &p) : x(p.x), y(p.y) {}

  Pt<T> operator+(const Pt<T> p) const { return Pt<T>(x + p.x, y + p.y); }
  Pt<T> operator-() const { return Pt<T>(-x, -y); }
  Pt<T> operator-(const Pt<T> p) const { return Pt<T>(x - p.x, y - p.y); }
  Pt<T> operator*(T t) const { return Pt<T>(x * t, y * t); }
  Pt<T> operator/(T t) const { return Pt<T>(x / t, y / t); }
  T dot(Pt<T> v) const { return x * v.x + y * v.y; }
  T cross(Pt<T> v) const { return x * v.y - y * v.x; }
  Pt<T> mid(const Pt<T> p) { return Pt<T>((x + p.x) / 2, (y + p.y) / 2); }
  T d2() { return x * x + y * y; }
  double d() { return sqrt(d2()); }

  Pt<T> rot(double th) {
    double c = cos(th), s = sin(th);
    return Pt<T>(c * x - s * y, s * x + c * y);
  }

  Pt<T> rot90() { return Pt<T>(-y, x); }

  bool operator==(const Pt<T> pt) const { return x == pt.x && y == pt.y; }
  bool operator<(const Pt<T> &pt) const {
    return x < pt.x || (x == pt.x && y < pt.y);
  }

  void print() { printf("(%d,%d)", x, y); }
};

typedef Pt<double> pt;
typedef pair<double,pt> pdpt;

struct Crc {
  pt cp;
  int r, v, a;
  Crc() {}

  void read() { scanf("%lf%lf%d%d%d", &cp.x, &cp.y, &r, &v, &a); }

  pt at(double t) const {
    double th = (t * v + a) * (PI / 180);
    return cp + pt(cos(th), sin(th)) * r;
  }
  
  pdpt meet(int w, pdpt &s) const {
    double st = s.first;
    pt sp = s.second;

    if (sp == cp) {
      double t = st + (double)r / w;
      return pdpt(t, at(t));
    }

    double vd = (cp - sp).d();
    double t0 = st + abs(vd - r) / w;
    double t1 = st + (vd + r) / w;

    for (int cnt = 0; cnt < CNT; cnt++) {
      double t = (t0 + t1) / 2;
      pt p = at(t);
      if (st + (p - sp).d() / w <= t) t1 = t;
      else t0 = t;
    }

    return pdpt(t1, at(t1));
  }
};

/* global variables */

Crc cs[MAX_N];
pdpt dp[NBITS][MAX_N];

/* subroutines */

template <typename T>
inline void setmin(T &a, T b) { if (a > b) a = b; }

/* main */

int main() {
  int n, w;
  scanf("%d%d", &n, &w);
  int nbits = 1 << n;

  for (int i = 0; i < n; i++) cs[i].read();

  for (int bits = 0; bits < nbits; bits++)
    fill(dp[bits], dp[bits] + n, pdpt(DINF, pt(0.0, 0.0)));
  dp[0][0] = pdpt(0.0, pt(0.0, 0.0));

  for (int bits = 0; bits < nbits; bits++)
    for (int i = 0; i < n; i++)
      if (dp[bits][i].first < DINF)
	for (int j = 0, bj = 1; j < n; j++, bj <<= 1)
	  if (! (bits & bj)) {
	    pdpt d1 = cs[j].meet(w, dp[bits][i]);
	    setmin<pdpt>(dp[bits | bj][j], d1);
	  }

  double mint = DINF;
  for (int i = 0; i < n; i++)
    setmin<double>(mint, dp[nbits - 1][i].first);

  printf("%.10lf\n", mint);
  return 0;
}
0