結果

問題 No.808 Kaiten Sushi?
ユーザー titiatitia
提出日時 2019-03-22 23:37:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 1,630 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 81,624 KB
実行使用メモリ 116,848 KB
最終ジャッジ日時 2023-10-19 10:54:42
合計ジャッジ時間 8,056 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,372 KB
testcase_01 AC 39 ms
53,372 KB
testcase_02 AC 40 ms
53,372 KB
testcase_03 AC 39 ms
53,372 KB
testcase_04 AC 39 ms
53,372 KB
testcase_05 AC 39 ms
53,372 KB
testcase_06 AC 39 ms
53,372 KB
testcase_07 AC 52 ms
64,216 KB
testcase_08 AC 52 ms
64,216 KB
testcase_09 AC 68 ms
71,024 KB
testcase_10 AC 63 ms
68,408 KB
testcase_11 AC 61 ms
66,344 KB
testcase_12 AC 64 ms
68,936 KB
testcase_13 AC 63 ms
68,944 KB
testcase_14 AC 50 ms
62,096 KB
testcase_15 AC 67 ms
71,016 KB
testcase_16 AC 65 ms
68,948 KB
testcase_17 AC 55 ms
64,340 KB
testcase_18 AC 43 ms
55,420 KB
testcase_19 AC 41 ms
53,372 KB
testcase_20 AC 43 ms
55,420 KB
testcase_21 AC 41 ms
53,372 KB
testcase_22 AC 43 ms
55,420 KB
testcase_23 AC 102 ms
89,116 KB
testcase_24 AC 97 ms
87,216 KB
testcase_25 AC 105 ms
89,596 KB
testcase_26 AC 103 ms
89,084 KB
testcase_27 AC 217 ms
113,120 KB
testcase_28 AC 115 ms
85,100 KB
testcase_29 AC 208 ms
110,868 KB
testcase_30 AC 156 ms
96,408 KB
testcase_31 AC 219 ms
115,344 KB
testcase_32 AC 231 ms
116,848 KB
testcase_33 AC 152 ms
95,844 KB
testcase_34 AC 167 ms
95,752 KB
testcase_35 AC 193 ms
103,836 KB
testcase_36 AC 149 ms
95,816 KB
testcase_37 AC 38 ms
53,372 KB
testcase_38 AC 38 ms
53,372 KB
testcase_39 AC 181 ms
106,972 KB
testcase_40 AC 88 ms
82,728 KB
testcase_41 AC 112 ms
83,940 KB
testcase_42 AC 164 ms
96,308 KB
testcase_43 AC 128 ms
89,132 KB
testcase_44 AC 144 ms
93,312 KB
testcase_45 AC 131 ms
89,204 KB
testcase_46 AC 106 ms
81,720 KB
testcase_47 AC 195 ms
112,384 KB
testcase_48 AC 193 ms
112,384 KB
testcase_49 AC 194 ms
112,384 KB
testcase_50 AC 192 ms
112,388 KB
testcase_51 AC 193 ms
112,384 KB
testcase_52 AC 128 ms
94,148 KB
testcase_53 AC 161 ms
110,516 KB
testcase_54 AC 39 ms
53,372 KB
testcase_55 AC 39 ms
53,372 KB
testcase_56 AC 40 ms
53,372 KB
testcase_57 AC 92 ms
88,800 KB
testcase_58 AC 103 ms
91,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,L=map(int,input().split())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))

X2=[[x,1] for x in X]
Y2=[[y,2] for y in Y]

ALL=X2+Y2
ALL.sort()

ALL_C=[ALL[0]+[1]]

for i in range(1,2*N):
    if ALL[i][1]==ALL[i-1][1]:
        ALL_C[-1][2]+=1
    else:
        ALL_C.append(ALL[i]+[1])

NOWkind=2
if NOWkind==ALL_C[0][1]==ALL_C[-1][1]:
    ALL_C[-1][2]+=ALL_C[0][2]
    ALL_C=ALL_C[1:]


NOW=0
EAT=0
ANS=0
LEN=len(ALL_C)
i=0

while EAT<2*N:
    #print(ALL_C,NOW,NOWkind,ANS)
    if i==LEN:
        i=0

        for j in range(LEN):
            if ALL_C[j][2]==0:
                continue
            else:
                ALL_C2=[ALL_C[j]]
                break

        for k in range(j+1,LEN):
            if ALL_C[k][2]==0:
                continue
            if ALL_C[k][1]==ALL_C2[-1][1]:
                ALL_C2[-1][2]+=ALL_C[k][2]
            else:
                ALL_C2.append(ALL_C[k])

        if NOWkind==ALL_C2[0][1]==ALL_C2[-1][1]:
            ALL_C2[-1][2]+=ALL_C2[0][2]
            ALL_C2=ALL_C2[1:]

        ALL_C=ALL_C2
        LEN=len(ALL_C)
            

        
    dist,kind,num=ALL_C[i]
    if num==0 or kind==NOWkind:
        i+=1
    else:
        if NOW<dist:
            ANS+=dist-NOW
            ALL_C[i][2]-=1
            EAT+=1
            NOW=dist
            NOWkind=kind
        else:
            ANS+=dist+(L-NOW)
            ALL_C[i][2]-=1
            EAT+=1
            NOW=dist
            NOWkind=kind
        i+=1

print(ANS)
            
    
    
0