結果

問題 No.731 等差数列がだいすき
ユーザー kohei2019kohei2019
提出日時 2022-03-27 10:39:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 760 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 76,160 KB
最終ジャッジ日時 2024-04-23 23:21:58
合計ジャッジ時間 16,374 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
76,032 KB
testcase_01 AC 96 ms
75,904 KB
testcase_02 AC 94 ms
75,988 KB
testcase_03 AC 351 ms
75,776 KB
testcase_04 AC 792 ms
75,904 KB
testcase_05 AC 336 ms
76,160 KB
testcase_06 AC 1,077 ms
76,028 KB
testcase_07 AC 663 ms
76,020 KB
testcase_08 AC 775 ms
75,764 KB
testcase_09 AC 970 ms
75,648 KB
testcase_10 AC 1,122 ms
75,780 KB
testcase_11 AC 109 ms
75,912 KB
testcase_12 AC 538 ms
76,160 KB
testcase_13 AC 718 ms
76,160 KB
testcase_14 AC 874 ms
76,040 KB
testcase_15 WA -
testcase_16 AC 593 ms
76,160 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1,314 ms
75,988 KB
testcase_20 AC 1,275 ms
75,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
lsa = list(map(int,input().split()))

def calc_r(p):#p=(x,y)
    r = 0
    x,y = p
    for i in range(N):
        r += abs(i*x+y-lsa[i])**2
    return r


def calc_y(x):
    low_y = -10**5
    high_y = 10**5
    cnt = 200
    while cnt:
        cnt -= 1
        c1 = (low_y*2+high_y)/3
        c2 = (low_y+high_y*2)/3
        if calc_r((x,c1)) < calc_r((x,c2)):
            high_y = c2
        else:
            low_y = c1
    return low_y

low_x = -10**5
high_x = 10**5
cnt = 200
while cnt:
    cnt -= 1
    c1 = (low_x * 2 + high_x) / 3
    c2 = (low_x + high_x * 2) / 3
    if calc_r((c1,calc_y(c1))) < calc_r((c2,calc_y(c2))):
        high_x = c2
    else:
        low_x = c1
print(calc_y(low_x),low_x)
print(calc_r((low_x,calc_y(low_x))))
0