結果

問題 No.450 ベー君のシャトルラン
ユーザー arukukaarukuka
提出日時 2016-11-14 16:51:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 2,717 bytes
コンパイル時間 2,292 ms
コンパイル使用メモリ 76,528 KB
実行使用メモリ 56,696 KB
最終ジャッジ日時 2023-08-17 06:44:16
合計ジャッジ時間 6,692 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
56,016 KB
testcase_01 AC 125 ms
56,160 KB
testcase_02 AC 130 ms
55,880 KB
testcase_03 AC 131 ms
56,076 KB
testcase_04 AC 142 ms
56,328 KB
testcase_05 AC 129 ms
56,056 KB
testcase_06 AC 130 ms
55,804 KB
testcase_07 AC 129 ms
56,336 KB
testcase_08 AC 129 ms
55,776 KB
testcase_09 AC 135 ms
56,060 KB
testcase_10 AC 133 ms
56,076 KB
testcase_11 AC 130 ms
56,696 KB
testcase_12 AC 131 ms
56,000 KB
testcase_13 AC 130 ms
56,040 KB
testcase_14 AC 127 ms
56,192 KB
testcase_15 AC 130 ms
56,320 KB
testcase_16 AC 130 ms
55,876 KB
testcase_17 AC 131 ms
56,076 KB
testcase_18 AC 132 ms
56,316 KB
testcase_19 AC 130 ms
56,044 KB
testcase_20 AC 129 ms
56,332 KB
testcase_21 AC 129 ms
55,724 KB
testcase_22 AC 128 ms
56,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  int vl, vr;
  int d;
  int w;

  /**
   * 想定解で誤差が酷いものになってないかチェック
   */
  BigDecimal checkai() {
    BigDecimal vl = new BigDecimal(this.vl, MathContext.DECIMAL128);
    BigDecimal vr = new BigDecimal(this.vr, MathContext.DECIMAL128);
    BigDecimal d = new BigDecimal(this.d, MathContext.DECIMAL128);
    BigDecimal w = new BigDecimal(this.w, MathContext.DECIMAL128);

    return w.multiply(d).divide(vl.add(vr), MathContext.DECIMAL128);
  }

  /**
   * 想定解
   * 算数
   */
  double souteikai() {
    double vl = (double) this.vl;
    double vr = (double) this.vr;
    double d = (double) this.d;
    double w = (double) this.w;

    return w * d / (vl + vr);
  }

  /**
   * 誤解
   * 数学
   * 誤差
   */
  double mendoksai() {
    double vl = (double) this.vl;
    double vr = (double) this.vr;
    double d = (double) this.d;
    double w = (double) this.w;

    double t1 = d / (w + vr);
    double d1 = d - t1 * (vl + vr);
    double h1 = d1 / d;
    double t2 = d1 / (w + vl);
    double d2 = d1 - t2 * (vl + vr);
    double h2 = d2 / d1;

    return w * (t1 + t2) / (1 - h1 * h2);
  }

  /**
   * 誤解
   * プログラムの力任せ
   * TLE、誤差
   */
  double gokai() {
    double vl = (double) this.vl;
    double vr = (double) this.vr;
    double d = (double) this.d;
    double w = (double) this.w;

    double ans = 0;

    while (d > 1e-7) {
      double t = d / (w + vr);
      ans += w * t;
      d -= t * (vl + vr);
      double tmp = vr;
      vr = vl;
      vl = tmp;
    }

    return ans;
  }

  void run() {
    vl = sc.nextInt();
    vr = sc.nextInt();
    d = sc.nextInt();
    w = sc.nextInt();

    assert (1 <= vl && vl <= 1_000_000_000L);
    assert (1 <= vr && vr <= 1_000_000_000L);
    assert (1 <= d && d <= 1_000_000_000L);
    assert (1 <= w && w <= 1_000_000_000L);
    assert (Math.max(vl, vr) < w);

    BigDecimal s = checkai();
    assert (Math.abs(BigDecimal.valueOf(souteikai()).subtract(s).doubleValue()) < 1e-6);
    if (max(d, w) / max(vl, vr) < 100_000) {
      assert (Math.abs(BigDecimal.valueOf(mendoksai()).subtract(s).doubleValue()) < 1e-6);
    }
    if (max(vl, vr, d, w) <= 100_000) {
      assert (Math.abs(BigDecimal.valueOf(gokai()).subtract(s).doubleValue()) < 1e-6);
    }

    System.out.println(s.toPlainString());
  }

  Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    new Main().run();
  }

  long max(long... a) {
    long r = Long.MIN_VALUE;
    for (long v : a) {
      r = Math.max(r, v);
    }
    return r;
  }
}
0