結果

問題 No.1413 Dynamic Sushi
ユーザー LayCurseLayCurse
提出日時 2021-02-28 22:09:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 142 ms / 4,000 ms
コード長 6,582 bytes
コンパイル時間 3,057 ms
コンパイル使用メモリ 216,224 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-02 22:32:02
合計ジャッジ時間 6,483 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 91 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 119 ms
5,248 KB
testcase_05 AC 129 ms
5,248 KB
testcase_06 AC 129 ms
5,248 KB
testcase_07 AC 142 ms
5,248 KB
testcase_08 AC 137 ms
5,248 KB
testcase_09 AC 121 ms
5,248 KB
testcase_10 AC 127 ms
5,248 KB
testcase_11 AC 135 ms
5,248 KB
testcase_12 AC 141 ms
5,248 KB
testcase_13 AC 142 ms
5,248 KB
testcase_14 AC 130 ms
5,248 KB
testcase_15 AC 133 ms
5,248 KB
testcase_16 AC 122 ms
5,248 KB
testcase_17 AC 128 ms
5,248 KB
testcase_18 AC 140 ms
5,248 KB
testcase_19 AC 126 ms
5,248 KB
testcase_20 AC 55 ms
5,248 KB
testcase_21 AC 2 ms
5,248 KB
testcase_22 AC 136 ms
5,248 KB
testcase_23 AC 139 ms
5,248 KB
testcase_24 AC 142 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(double &x){
  int k;
  int m=0;
  int p=0;
  double r = 1;
  x = 0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m = 1;
      break;
    }
    if(k=='.'){
      p = 1;
      break;
    }
    if('0'<=k&&k<='9'){
      x = k - '0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k=='.'){
      p = 1;
      continue;
    }
    if(k<'0'||k>'9'){
      break;
    }
    if(p){
      r *= 0.1;
      x += r * (k - '0');
    }
    else{
      x = x * 10 + k - '0';
    }
  }
  if(m){
    x = -x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
int WRITER_DOUBLE_DIGIT = 15;
inline int writerDigit_double(){
  return WRITER_DOUBLE_DIGIT;
}
inline void writerDigit_double(int d){
  WRITER_DOUBLE_DIGIT = d;
}
inline void wt_L(double x){
  const int d = WRITER_DOUBLE_DIGIT;
  int k;
  int r;
  double v;
  if(x!=x || (x==x+1 && x==2*x)){
    my_putchar_unlocked('E');
    my_putchar_unlocked('r');
    my_putchar_unlocked('r');
    return;
  }
  if(x < 0){
    my_putchar_unlocked('-');
    x = -x;
  }
  x += 0.5 * pow(0.1, d);
  r = 0;
  v = 1;
  while(x >= 10*v){
    v *= 10;
    r++;
  }
  while(r >= 0){
    r--;
    k = floor(x / v);
    if(k >= 10){
      k = 9;
    }
    if(k <= -1){
      k = 0;
    }
    x -= k * v;
    v *= 0.1;
    my_putchar_unlocked(k + '0');
  }
  if(d > 0){
    my_putchar_unlocked('.');
    v = 1;
    for(r=(0);r<(d);r++){
      v *= 0.1;
      k = floor(x / v);
      if(k >= 10){
        k = 9;
      }
      if(k <= -1){
        k = 0;
      }
      x -= k * v;
      my_putchar_unlocked(k + '0');
    }
  }
}
template<class T> inline T pow2_L(T a){
  return a*a;
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
double W;
double X[13];
double Y[13];
double R[13];
double V[13];
double A[13];
double dp[13][10000];
int main(){
  int i, mask;
  double res = 1e150;
  double tmp;
  double x;
  double y;
  double dx;
  double dy;
  double d;
  double r;
  double mn;
  double mx;
  rd(N);
  rd(W);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(X[Lj4PdHRW]);
      rd(Y[Lj4PdHRW]);
      rd(R[Lj4PdHRW]);
      rd(V[Lj4PdHRW]);
      rd(A[Lj4PdHRW]);
    }
  }
  N++;
  for(i=(0);i<(N);i++){
    int j;
    for(j=(0);j<(1<<N);j++){
      dp[i][j] = 1e150;
    }
  }
  dp[N-1][1<<(N-1)] = 0;
  for(mask=(0);mask<(1<<N);mask++){
    for(i=(0);i<(N);i++){
      if(dp[i][mask] < 1e150){
        int j;
        for(j=(0);j<(N);j++){
          if(!((mask) &(1<<(j)))){
            if(dp[j][mask|(1<<j)] <= dp[i][mask]){
              continue;
            }
            x = X[i] + R[i] * cos((V[i] * dp[i][mask] + A[i]) * PI / 180);
            y = Y[i] + R[i] * sin((V[i] * dp[i][mask] + A[i]) * PI / 180);
            r = sqrt((pow2_L((x - X[j])))+(pow2_L((y - Y[j]))));
            mn =max_L(r - R[j], 0)/ W;
            mx = (r + R[j]) / W;
            double hCmBdyQB;
            double V9aVTaxx;
            double APIVbQlN;
            hCmBdyQB = mn;
            V9aVTaxx = mx;
            for(;;){
              APIVbQlN = (hCmBdyQB + V9aVTaxx) / 2;
              if(V9aVTaxx - hCmBdyQB < 5e-7){
                break;
              }
              if(hCmBdyQB > 0 && V9aVTaxx - hCmBdyQB < hCmBdyQB * 5e-7){
                break;
              }
              if(V9aVTaxx < 0 && V9aVTaxx - hCmBdyQB < (-V9aVTaxx) * 5e-7){
                break;
              }
              if(APIVbQlN == hCmBdyQB || APIVbQlN == V9aVTaxx){
                break;
              }
              dx = x - (X[j] + R[j] * cos((V[j] * (dp[i][mask]+APIVbQlN) + A[j]) * PI / 180));
              dy = y - (Y[j] + R[j] * sin((V[j] * (dp[i][mask]+APIVbQlN) + A[j]) * PI / 180));
              d = ((pow2_L(dx))+(pow2_L(dy)));
              if(d <= (W * APIVbQlN) * (W * APIVbQlN)){
                V9aVTaxx = APIVbQlN;
              }
              else{
                hCmBdyQB = APIVbQlN;
              }
            }
            tmp =((hCmBdyQB + V9aVTaxx) / 2);
            chmin(dp[j][mask|(1<<j)], dp[i][mask] + tmp);
          }
        }
      }
    }
  }
  for(i=(0);i<(N);i++){
    chmin(res, dp[i][(1<<N)-1]);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay version 20210227-1

// --- original code ---
// int N; double W, X[13], Y[], R[], V[], A[];
// double dp[13][1d4];
// {
//   double res = double_inf, tmp, x, y, dx, dy, d, r, mn, mx;
//   rd(N,W,(X,Y,R,V,A)(N));
//   N++;
//   rep(i,N) rep(j,1<<N) dp[i][j] = double_inf;
//   dp[N-1][1<<(N-1)] = 0;
//   rep(mask,1<<N) rep(i,N) if(dp[i][mask] < double_inf){
//     rep(j,N) if(!BIT_ith(mask,j)){
//       if(dp[j][mask|(1<<j)] <= dp[i][mask]) continue;
//       x = X[i] + R[i] * cos((V[i] * dp[i][mask] + A[i]) * PI / 180);
//       y = Y[i] + R[i] * sin((V[i] * dp[i][mask] + A[i]) * PI / 180);
//       r = sqrt((x - X[j]) ** 2 + (y - Y[j]) ** 2);
//       mn = max(r - R[j], 0) / W;
//       mx = (r + R[j]) / W;
//       tmp = bsearch_min[double,t,mn,mx,E=5e-7][
//         dx = x - (X[j] + R[j] * cos((V[j] * (dp[i][mask]+t) + A[j]) * PI / 180));
//         dy = y - (Y[j] + R[j] * sin((V[j] * (dp[i][mask]+t) + A[j]) * PI / 180));
//         d = (dx ** 2 + dy ** 2);
//       ](d <= (W * t) * (W * t));
//       dp[j][mask|(1<<j)] <?= dp[i][mask] + tmp;
//     }
//   }
//   rep(i,N) res <?= dp[i][(1<<N)-1];
//   wt(res);
// }
0