結果
問題 | No.764 浮動点 |
ユーザー | 37zigen |
提出日時 | 2018-12-01 19:56:46 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 284 ms / 1,500 ms |
コード長 | 3,574 bytes |
コンパイル時間 | 2,161 ms |
コンパイル使用メモリ | 78,540 KB |
実行使用メモリ | 57,144 KB |
最終ジャッジ日時 | 2024-06-27 00:02:46 |
合計ジャッジ時間 | 9,355 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 119 ms
53,848 KB |
testcase_01 | AC | 120 ms
53,592 KB |
testcase_02 | AC | 122 ms
53,908 KB |
testcase_03 | AC | 178 ms
54,244 KB |
testcase_04 | AC | 250 ms
54,472 KB |
testcase_05 | AC | 198 ms
54,236 KB |
testcase_06 | AC | 257 ms
54,564 KB |
testcase_07 | AC | 188 ms
54,120 KB |
testcase_08 | AC | 238 ms
54,688 KB |
testcase_09 | AC | 204 ms
54,900 KB |
testcase_10 | AC | 266 ms
55,580 KB |
testcase_11 | AC | 199 ms
53,984 KB |
testcase_12 | AC | 279 ms
55,888 KB |
testcase_13 | AC | 284 ms
56,740 KB |
testcase_14 | AC | 281 ms
57,144 KB |
testcase_15 | AC | 274 ms
55,824 KB |
testcase_16 | AC | 282 ms
55,756 KB |
testcase_17 | AC | 280 ms
57,032 KB |
testcase_18 | AC | 268 ms
55,752 KB |
testcase_19 | AC | 268 ms
55,696 KB |
testcase_20 | AC | 277 ms
56,820 KB |
testcase_21 | AC | 278 ms
56,716 KB |
testcase_22 | AC | 280 ms
56,756 KB |
testcase_23 | AC | 279 ms
56,296 KB |
testcase_24 | AC | 278 ms
56,052 KB |
testcase_25 | AC | 149 ms
54,040 KB |
ソースコード
//制約の確認 import java.util.*; import java.io.*; import java.math.*; class Main { public static void main(String[] args) { new Main().run(); } void run() { Scanner sc = new Scanner(); int N = sc.nextInt(); if (!(3 <= N && N <= 1000)) throw new AssertionError(); double[] L = new double[N + 2]; for (int i = 0; i <= N + 1; ++i) { L[i] = sc.nextInt(); if (!(1 <= L[i] && L[i] <= 1000)) throw new AssertionError(); } double[] Ri1 = new double[N + 2]; double[] Ro1 = new double[N + 2]; double[] Ri2 = new double[N + 2]; double[] Ro2 = new double[N + 2]; for (int i = 1; i <= N; ++i) { Ro1[i] = Ro1[i - 1] + L[i]; } Ri1[1] = Ro1[1]; for (int i = 2; i <= N; ++i) { Ri1[i] = abs(Ri1[i - 1], Ro1[i - 1], L[i]); } for (int i = N; i >= 1; --i) { Ro2[i] = Ro2[i + 1] + L[i + 1]; } Ri2[N] = Ro2[N]; for (int i = N - 1; i >= 1; --i) { Ri2[i] = abs(Ri2[i + 1], Ro2[i + 1], L[i + 1]); } for (int i = 1; i <= N; ++i) { System.out.println(String.format("%.20f", solve(Ro1[i], Ri1[i], Ro2[i], Ri2[i], L[0]))); } } double solve(double Ro1, double Ri1, double Ro2, double Ri2, double L) { return f(Ro1, Ro2, L) - f(Ro1, Ri2, L) - f(Ri1, Ro2, L) + f(Ri1, Ri2, L); } double abs(double a, double b, double d) { if (a <= d && d <= b) return 0; return Math.min(Math.abs(d - a), Math.abs(d - b)); } double f(double a, double b, double L) { if (L >= a + b) return 0; if (b >= a + L) return a * a * Math.PI; if (a >= b + L) return b * b * Math.PI; double x = 0.5 * L + (a * a - b * b) / (2 * L); double y = Math.sqrt(a * a - x * x); double ang1 = Math.atan2(y, x); double ang2 = Math.atan2(y, L - x); if (ang1 < 0) ang1 += Math.PI; if (ang2 < 0) ang2 += Math.PI; return g(2 * ang1, a) + g(2 * ang2, b); } double g(double ang, double r) { return 0.5 * r * r * (ang - Math.sin(ang)); } void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } } class Scanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } private void skipUnprintable() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; } public boolean hasNext() { skipUnprintable(); return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { return (int) nextLong(); } }