Submission #937637


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 GOLDEN_RATIO = (1.0 + Math.sqrt(5)) / 2.0;

  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);
  }

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

  static double p;

  void run() {
    p = sc.nextDouble();
    double x = goldenSectionSearch(0, p,
        Main::f,
        Comparator.comparingDouble(Double::doubleValue).reversed()
    );
    System.out.println(f(x));
  }

  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;
  }
}

Submission Info

Submission Time
Task B - ムーアの法則
User arukuka
Language Java8 (OpenJDK 1.8.0)
Score 100
Code Size 3088 Byte
Status AC
Exec Time 265 ms
Memory 16452 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 265 ms 16452 KB
02.txt AC 245 ms 15680 KB
03.txt AC 234 ms 15944 KB
04.txt AC 236 ms 15932 KB
05.txt AC 234 ms 15824 KB
06.txt AC 239 ms 15692 KB
07.txt AC 245 ms 15808 KB
08.txt AC 238 ms 16064 KB
09.txt AC 234 ms 15808 KB
10.txt AC 241 ms 15828 KB
11.txt AC 241 ms 15816 KB
12.txt AC 240 ms 15684 KB
13.txt AC 238 ms 15932 KB
14.txt AC 236 ms 15812 KB
15.txt AC 237 ms 16064 KB
16.txt AC 234 ms 15700 KB
17.txt AC 249 ms 15828 KB
18.txt AC 238 ms 15684 KB
19.txt AC 237 ms 15824 KB
20.txt AC 238 ms 15816 KB
21.txt AC 241 ms 15688 KB
22.txt AC 248 ms 15696 KB
23.txt AC 233 ms 15696 KB
24.txt AC 235 ms 15684 KB
25.txt AC 245 ms 15828 KB
sample_01.txt AC 239 ms 15680 KB
sample_02.txt AC 234 ms 15948 KB
sample_03.txt AC 238 ms 15700 KB