結果
| 問題 |
No.1385 Simple Geometry 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-25 03:43:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 327 ms / 500 ms |
| コード長 | 1,856 bytes |
| コンパイル時間 | 356 ms |
| コンパイル使用メモリ | 82,836 KB |
| 実行使用メモリ | 222,628 KB |
| 最終ジャッジ日時 | 2024-09-29 10:41:58 |
| 合計ジャッジ時間 | 26,638 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 65 |
ソースコード
## https://yukicoder.me/problems/no/1385
import math
def main():
N, L = map(int, input().split())
T = list(map(int, input().split()))
# sin, cosの累積和
f_list = [0] * N
g_list = [0] * N
f = 0
g = 0
for i in reversed(range(N)):
t = (2 * math.pi * T[i]) / L
f += math.sin(t)
g += math.cos(t)
f_list[i] = f
g_list[i] = g
# 複雑な計算式の累積和
x_cum_list = [0] * N
x_cum = 0
xcos_cum_list = [0] * N
xcos_cum = 0
xsin_cum_list = [0] * N
xsin_cum = 0
ysin_cum_list = [0] * N
ysin_cum = 0
ycos_cum_list = [0] * N
ycos_cum = 0
for i in reversed(range(N - 1)):
f = f_list[i + 1]
g = g_list[i + 1]
t = (2 * math.pi * T[i]) / L
cos_t = math.cos(t)
sin_t = math.sin(t)
x = f * cos_t - g * sin_t
y = (N - 1 - i) - g * cos_t - f * sin_t
x_cum += x
x_cum_list[i] = x_cum
xcos_cum += x * cos_t
xcos_cum_list[i] = xcos_cum
xsin_cum += x * sin_t
xsin_cum_list[i] = xsin_cum
ysin_cum += y * sin_t
ysin_cum_list[i] = ysin_cum
ycos_cum += y * cos_t
ycos_cum_list[i] = ycos_cum
#
cum_value_list = [0] * N
for i in reversed(range(N - 2)):
t = (2 * math.pi * T[i]) / L
cos_t = math.cos(t)
sin_t = math.sin(t)
value = x_cum_list[i + 1] / 2
value -= xcos_cum_list[i + 1] * cos_t / 2
value -= xsin_cum_list[i + 1] * sin_t / 2
value += ysin_cum_list[i + 1] * cos_t / 2
value -= ycos_cum_list[i + 1] * sin_t / 2
cum_value_list[i] = value
ans = (N * (N - 1) * (N - 2)) // 6
answer = 0
for i in range(N):
answer += cum_value_list[i] / ans
print(answer)
if __name__ == "__main__":
main()