結果

問題 No.2652 [Cherry 6th Tune N] Δρονε χιρχλινγ
ユーザー titiatitia
提出日時 2024-02-28 02:24:22
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,234 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 87,648 KB
最終ジャッジ日時 2024-02-28 02:24:35
合計ジャッジ時間 12,799 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
54,016 KB
testcase_01 AC 326 ms
79,892 KB
testcase_02 AC 312 ms
79,792 KB
testcase_03 AC 358 ms
80,548 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from random import randint,shuffle

T=int(input())
for tests in range(T):
    N,L=map(int,input().split())
    P=[list(map(int,input().split())) for i in range(N)]

    ANS=list(range(N))
    shuffle(ANS)
    
    NOW=0

    for i in range(1,len(ANS)):
        x,y=P[ANS[i]]
        z,w=P[ANS[i-1]]

        NOW+=abs(x-z)+abs(y-w)

    while NOW>998*L:
        c0=randint(0,len(ANS)-1)
        c1=randint(0,len(ANS)-1)

        if x==y:
            continue

        NOW2=NOW

        for i in [c0,c0+1,c1,c1+1] :
            if 0<=i-1 and i<len(ANS):
                x,y=P[ANS[i]]
                z,w=P[ANS[i-1]]

                NOW2-=abs(x-z)+abs(y-w)

        ANS[c0],ANS[c1]=ANS[c1],ANS[c0]

        for i in [c0,c0+1,c1,c1+1] :
            if 0<=i-1 and i<len(ANS):
                x,y=P[ANS[i]]
                z,w=P[ANS[i-1]]

                NOW2+=abs(x-z)+abs(y-w)

        if NOW2<=NOW:
            NOW=NOW2
            pass
        else:
            ANS[c0],ANS[c1]=ANS[c1],ANS[c0]

    print(len(ANS)+1)
    for i in range(len(ANS)):
        x,y=P[ANS[i]]

        print(x,y)

    x,y=P[ANS[0]]
    print(x,y)
            
        

        
                
        
    
        
0