結果

問題 No.731 等差数列がだいすき
ユーザー shotoyooshotoyoo
提出日時 2021-06-19 18:11:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 1,500 ms
コード長 833 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 76,456 KB
最終ジャッジ日時 2023-09-05 01:06:17
合計ジャッジ時間 3,053 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,428 KB
testcase_01 AC 72 ms
71,324 KB
testcase_02 AC 73 ms
71,492 KB
testcase_03 AC 77 ms
71,684 KB
testcase_04 AC 78 ms
75,852 KB
testcase_05 AC 73 ms
71,580 KB
testcase_06 AC 79 ms
75,620 KB
testcase_07 AC 80 ms
76,344 KB
testcase_08 AC 78 ms
75,872 KB
testcase_09 AC 77 ms
75,808 KB
testcase_10 AC 77 ms
75,756 KB
testcase_11 AC 73 ms
71,376 KB
testcase_12 AC 76 ms
76,196 KB
testcase_13 AC 76 ms
75,712 KB
testcase_14 AC 78 ms
76,016 KB
testcase_15 AC 77 ms
75,752 KB
testcase_16 AC 77 ms
76,456 KB
testcase_17 AC 76 ms
75,736 KB
testcase_18 AC 76 ms
75,792 KB
testcase_19 AC 77 ms
75,796 KB
testcase_20 AC 77 ms
75,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


# 1次方程式cx
def solve(a,b,c,d,e,f):
    """
    ax + by + c = 0
    dx + ey + f = 0
    """
    v = (a*e-b*d)
    if v==0:
        # 縮退している
        if b!=0:
            return (0, -c/b)
        else:
            return (-c/a,0)
    x = - (c*e - f*b) / v
    y = (d*c - a*f) / v
#     print(a*x+b*y+c, d*x+e*y+f)
    return (x,y)

n = int(input())
aa = list(map(int, input().split()))
a = n
b = n*(n+1)//2
c = -sum(aa)
d = n*(n+1)//2
e = n*(n+1)*(2*n+1)//6
f = -sum(((i+1)*aa[i] for i in range(n)))
x,y = solve(a,b,c,d,e,f)
print(x+y,y)
print(sum((x+(i+1)*y-aa[i])**2 for i in range(n)))
0