結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
76,128 KB
testcase_01 AC 67 ms
76,024 KB
testcase_02 AC 67 ms
76,076 KB
testcase_03 AC 140 ms
76,160 KB
testcase_04 AC 254 ms
76,160 KB
testcase_05 AC 142 ms
75,852 KB
testcase_06 AC 333 ms
76,256 KB
testcase_07 AC 214 ms
76,416 KB
testcase_08 AC 238 ms
76,032 KB
testcase_09 AC 280 ms
76,360 KB
testcase_10 AC 326 ms
75,852 KB
testcase_11 AC 75 ms
76,032 KB
testcase_12 AC 189 ms
76,204 KB
testcase_13 AC 235 ms
76,108 KB
testcase_14 AC 273 ms
76,228 KB
testcase_15 WA -
testcase_16 AC 195 ms
76,208 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 369 ms
76,256 KB
testcase_20 AC 367 ms
75,840 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 = 100
    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 = 100
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