Submission #937657


Source Code Expand

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.function.BiFunction;
import java.util.function.Function;

public class Main {
  Scanner sc = new Scanner(System.in);

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


  double f(double x) {
    return x + p / Math.pow(2.0, x / 1.5);
  }

  double f_(double x) {
    return 1.0 - p * Math.log(2) / 1.5 * Math.pow(2.0, -x / 1.5);
  }

  double p;

  void run() {
    p = sc.nextDouble();

    double left = 0;
    double right = p;
    while (right - left > 1e-9) {
      double mid = (left + right) / 2.0;
      double v = f_(mid);
      if (v > 0) {
        right = mid;
      } else {
        left = mid;
      }
    }

    System.out.println(f(right));
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }

  class BIT<T> {
    int n;
    ArrayList<T> bit;
    BiFunction<T, T, T> bif;

    BIT(int n, BiFunction<T, T, T> bif, T defaultValue) {
      this.n = n;
      bit = new ArrayList<>(n + 1);
      for (int i = 0; i < n + 1; ++i) {
        bit.add(defaultValue);
      }
      this.bif = bif;
    }

    void update(int i, T v) {
      for (int x = i; x <= n; x += x & -x) {
        bit.set(x, bif.apply(bit.get(x), v));
      }
    }

    T reduce(int i, T defaultValue) {
      T ret = defaultValue;
      for (int x = i; x > 0; x -= x & -x) {
        ret = bif.apply(ret, bit.get(x));
      }
      return ret;
    }
  }

  long MOD = 1_000_000_007;

  long pow(long a, long r) {
    long sum = 1;
    while (r > 0) {
      if ((r & 1) == 1) {
        sum *= a;
        sum %= MOD;
      }
      a *= a;
      a %= MOD;
      r >>= 1;
    }
    return sum;
  }

  long C(int n, int r) {
    long sum = 1;
    for (int i = n; 0 < i; --i) {
      sum *= i;
      sum %= MOD;
    }
    long s = 1;
    for (int i = r; 0 < i; --i) {
      s *= i;
      s %= MOD;
    }
    sum *= pow(s, MOD - 2);
    sum %= MOD;

    long t = 1;
    for (int i = n - r; 0 < i; --i) {
      t *= i;
      t %= MOD;
    }
    sum *= pow(t, MOD - 2);
    sum %= MOD;

    return sum;
  }

  double GOLDEN_RATIO = (1.0 + Math.sqrt(5)) / 2.0;

  /**
   * 黄金分割探索
   *
   * @param left  下限
   * @param right 上限
   * @param f     探索する関数
   * @param comp  上に凸な関数を探索するときは、Comparator.comparingDouble(Double::doubleValue)
   *              下に凸な関数を探索するときは、Comparator.comparingDouble(Double::doubleValue).reversed()
   * @return 極値の座標x
   */
  double goldenSectionSearch(double left, double right, Function<Double, Double> f, Comparator<Double> comp) {
    double c1 = divideInternally(left, right, 1, GOLDEN_RATIO);
    double c2 = divideInternally(left, right, GOLDEN_RATIO, 1);
    double d1 = f.apply(c1);
    double d2 = f.apply(c2);
    while (right - left > 1e-9) {
      if (comp.compare(d1, d2) > 0) {
        right = c2;
        c2 = c1;
        d2 = d1;
        c1 = divideInternally(left, right, 1, GOLDEN_RATIO);
        d1 = f.apply(c1);
      } else {
        left = c1;
        c1 = c2;
        d1 = d2;
        c2 = divideInternally(left, right, GOLDEN_RATIO, 1);
        d2 = f.apply(c2);
      }
    }
    return right;
  }

  /**
   * [a,b]をm:nに内分する点を返す
   */
  double divideInternally(double a, double b, double m, double n) {
    return (n * a + m * b) / (m + n);
  }
}

Submission Info

Submission Time
Task B - ムーアの法則
User arukuka
Language Java8 (OpenJDK 1.8.0)
Score 100
Code Size 3694 Byte
Status AC
Exec Time 149 ms
Memory 11348 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 25
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt
Case Name Status Exec Time Memory
01.txt AC 148 ms 11140 KB
02.txt AC 147 ms 11144 KB
03.txt AC 147 ms 11212 KB
04.txt AC 141 ms 11216 KB
05.txt AC 148 ms 10696 KB
06.txt AC 147 ms 11140 KB
07.txt AC 137 ms 11216 KB
08.txt AC 136 ms 10696 KB
09.txt AC 136 ms 10700 KB
10.txt AC 147 ms 11212 KB
11.txt AC 145 ms 11212 KB
12.txt AC 137 ms 11348 KB
13.txt AC 138 ms 11216 KB
14.txt AC 145 ms 11344 KB
15.txt AC 147 ms 11144 KB
16.txt AC 138 ms 11340 KB
17.txt AC 138 ms 11340 KB
18.txt AC 148 ms 11220 KB
19.txt AC 147 ms 11340 KB
20.txt AC 138 ms 11348 KB
21.txt AC 136 ms 11344 KB
22.txt AC 149 ms 11344 KB
23.txt AC 138 ms 11272 KB
24.txt AC 137 ms 11212 KB
25.txt AC 147 ms 11336 KB
sample_01.txt AC 136 ms 11216 KB
sample_02.txt AC 146 ms 10700 KB
sample_03.txt AC 147 ms 11212 KB