結果

問題 No.2488 Mod Sum Maximization
ユーザー hirayuu_ychirayuu_yc
提出日時 2023-09-29 22:01:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 951 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 128,996 KB
最終ジャッジ日時 2023-09-29 22:03:01
合計ジャッジ時間 68,875 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,582 ms
78,908 KB
testcase_01 AC 1,580 ms
78,828 KB
testcase_02 AC 1,580 ms
78,840 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1,579 ms
113,384 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1,579 ms
118,276 KB
testcase_22 WA -
testcase_23 AC 1,581 ms
123,724 KB
testcase_24 WA -
testcase_25 AC 1,577 ms
78,504 KB
testcase_26 WA -
testcase_27 AC 1,580 ms
105,076 KB
testcase_28 AC 1,586 ms
105,048 KB
testcase_29 AC 1,576 ms
104,940 KB
testcase_30 AC 1,579 ms
94,172 KB
testcase_31 WA -
testcase_32 AC 1,579 ms
117,860 KB
testcase_33 AC 1,576 ms
79,312 KB
testcase_34 AC 1,578 ms
123,636 KB
testcase_35 AC 1,578 ms
92,572 KB
testcase_36 AC 1,585 ms
78,840 KB
testcase_37 AC 1,582 ms
78,560 KB
testcase_38 AC 1,591 ms
78,748 KB
testcase_39 AC 1,577 ms
79,124 KB
testcase_40 AC 1,577 ms
78,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import time
import random

t1=time.time()
N=int(input())
A=list(map(int,input().split()))
ans=0
for i in A:
    ans+=i
ans-=A[-1]
ans+=A[-1]%A[0]
pos={0}
while time.time()-t1<1.5:
    lf=random.choice(list(pos))
    ri=random.randint(0,N-1)
    while lf==ri:
        ri=random.randint(0,N-1)
    pre=ans
    new=ans
    used={(lf-1)%N,lf,(ri-1)%N,ri}
    for i in used:
        new-=A[i]%A[(i+1)%N]
    A[lf],A[ri]=A[ri],A[lf]
    for i in used:
        new+=A[i]%A[(i+1)%N]
    if pre>new:
        A[lf],A[ri]=A[ri],A[lf]
    else:
        ans=new
        if A[lf-1]<A[lf]:
            pos.add((lf-1)%N)
        else:
            pos.discard(lf-1)
        if A[ri-1]<A[ri]:
            pos.add((ri-1)%N)
        else:
            pos.discard(ri-1)
        if A[lf]<A[(lf+1)%N]:
            pos.add(lf)
        else:
            pos.discard(lf)
        if A[ri]<A[(ri+1)%N]:
            pos.add(ri)
        else:
            pos.discard(ri)
print(ans)
0