結果
問題 | No.2488 Mod Sum Maximization |
ユーザー |
|
提出日時 | 2023-09-29 22:01:48 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 951 bytes |
コンパイル時間 | 359 ms |
コンパイル使用メモリ | 82,368 KB |
実行使用メモリ | 118,008 KB |
最終ジャッジ日時 | 2024-07-22 16:02:37 |
合計ジャッジ時間 | 67,198 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 WA * 21 |
ソースコード
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)