結果

問題 No.764 浮動点
ユーザー hiromi_ayasehiromi_ayase
提出日時 2018-12-13 13:38:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 354 ms / 1,500 ms
コード長 3,955 bytes
コンパイル時間 4,487 ms
コンパイル使用メモリ 88,900 KB
実行使用メモリ 63,160 KB
最終ジャッジ日時 2023-10-25 09:21:02
合計ジャッジ時間 11,534 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
57,372 KB
testcase_01 AC 145 ms
57,360 KB
testcase_02 AC 145 ms
55,288 KB
testcase_03 AC 236 ms
57,864 KB
testcase_04 AC 302 ms
58,784 KB
testcase_05 AC 233 ms
57,692 KB
testcase_06 AC 307 ms
60,876 KB
testcase_07 AC 245 ms
58,260 KB
testcase_08 AC 321 ms
60,928 KB
testcase_09 AC 252 ms
57,904 KB
testcase_10 AC 349 ms
62,508 KB
testcase_11 AC 273 ms
58,240 KB
testcase_12 AC 353 ms
63,032 KB
testcase_13 AC 352 ms
62,528 KB
testcase_14 AC 352 ms
62,980 KB
testcase_15 AC 332 ms
61,492 KB
testcase_16 AC 341 ms
61,552 KB
testcase_17 AC 349 ms
63,160 KB
testcase_18 AC 321 ms
61,500 KB
testcase_19 AC 320 ms
61,396 KB
testcase_20 AC 322 ms
61,136 KB
testcase_21 AC 334 ms
61,360 KB
testcase_22 AC 349 ms
62,960 KB
testcase_23 AC 350 ms
62,624 KB
testcase_24 AC 354 ms
62,908 KB
testcase_25 AC 177 ms
57,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

public class Main {
  private static void solve() {
    int n = ni();
    double d = ni();
    double[] l = new double[n + 1];
    for (int i = 0; i <= n; i ++) {
      l[i] = ni();
    }
    
    //0:left min, 1:left max, 2:right min, 3:right max
    double[][] r = new double[n][4];
    for (int i = 0; i < n; i ++) {
      double sumLeft = 0;
      double maxLeft = 0;
      double sumRight = 0;
      double maxRight = 0;
      for (int j = 0; j <= i; j ++) {
        sumLeft += l[j];
        maxLeft = Math.max(maxLeft, l[j]);
      }
      for (int j = i + 1; j <= n; j ++) {
        sumRight += l[j];
        maxRight = Math.max(maxRight, l[j]);
      }
      r[i][0] = Math.max(maxLeft * 2 - sumLeft, 0);
      r[i][1] = sumLeft;
      r[i][2] = Math.max(maxRight * 2 - sumRight, 0);
      r[i][3] = sumRight;
    }
    
    for (int i = 0; i < n; i ++) {
      double ret = 0;
      ret += s(r[i][1], r[i][3], d);
      ret -= s(r[i][0], r[i][3], d);
      ret -= s(r[i][1], r[i][2], d);
      ret += s(r[i][0], r[i][2], d);
      System.out.printf("%.9f\n", ret);
    }
  }
  
  private static double s(double r1, double r2, double d) {
    if (r1 + r2 <= d) return 0;
    if (Math.max(r1, r2) - Math.min(r1, r2) >= d) {
      double r = Math.min(r1, r2);
      return r * r * Math.PI;
    }

    double theta1 = Math.acos((r1 * r1 + d * d - r2 * r2) / (2 * r1 * d));
    double theta2 = Math.acos((r2 * r2 + d * d - r1 * r1) / (2 * r2 * d));
    
    double ret = 0;
    ret += r1 * r1 * (theta1 - Math.sin(theta1 * 2) / 2);
    ret += r2 * r2 * (theta2 - Math.sin(theta2 * 2) / 2);
    return ret;
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

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

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}
0