結果

問題 No.731 等差数列がだいすき
ユーザー shotoyoo
提出日時 2021-06-19 18:11:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 44 ms / 1,500 ms
コード長 833 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 59,264 KB
最終ジャッジ日時 2024-06-22 22:14:25
合計ジャッジ時間 1,811 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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