結果

問題 No.808 Kaiten Sushi?
ユーザー titiatitia
提出日時 2019-03-22 23:39:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 567 ms / 2,000 ms
コード長 1,630 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 12,020 KB
実行使用メモリ 46,652 KB
最終ジャッジ日時 2023-10-19 10:55:05
合計ジャッジ時間 13,628 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,232 KB
testcase_01 AC 33 ms
10,232 KB
testcase_02 AC 31 ms
10,232 KB
testcase_03 AC 32 ms
10,232 KB
testcase_04 AC 29 ms
10,232 KB
testcase_05 AC 30 ms
10,232 KB
testcase_06 AC 30 ms
10,232 KB
testcase_07 AC 36 ms
10,852 KB
testcase_08 AC 37 ms
10,976 KB
testcase_09 AC 41 ms
11,200 KB
testcase_10 AC 37 ms
10,876 KB
testcase_11 AC 37 ms
10,696 KB
testcase_12 AC 41 ms
10,872 KB
testcase_13 AC 36 ms
10,764 KB
testcase_14 AC 33 ms
10,392 KB
testcase_15 AC 41 ms
11,108 KB
testcase_16 AC 39 ms
10,932 KB
testcase_17 AC 35 ms
10,436 KB
testcase_18 AC 33 ms
10,304 KB
testcase_19 AC 31 ms
10,252 KB
testcase_20 AC 33 ms
10,308 KB
testcase_21 AC 31 ms
10,256 KB
testcase_22 AC 33 ms
10,300 KB
testcase_23 AC 202 ms
28,592 KB
testcase_24 AC 170 ms
24,940 KB
testcase_25 AC 196 ms
27,480 KB
testcase_26 AC 192 ms
26,596 KB
testcase_27 AC 452 ms
40,816 KB
testcase_28 AC 146 ms
19,412 KB
testcase_29 AC 437 ms
39,124 KB
testcase_30 AC 275 ms
29,100 KB
testcase_31 AC 486 ms
42,268 KB
testcase_32 AC 546 ms
46,652 KB
testcase_33 AC 271 ms
29,060 KB
testcase_34 AC 322 ms
31,944 KB
testcase_35 AC 394 ms
36,536 KB
testcase_36 AC 275 ms
28,708 KB
testcase_37 AC 32 ms
10,232 KB
testcase_38 AC 30 ms
10,232 KB
testcase_39 AC 442 ms
35,312 KB
testcase_40 AC 124 ms
16,372 KB
testcase_41 AC 140 ms
18,056 KB
testcase_42 AC 377 ms
31,560 KB
testcase_43 AC 182 ms
20,500 KB
testcase_44 AC 291 ms
26,504 KB
testcase_45 AC 179 ms
20,504 KB
testcase_46 AC 112 ms
16,020 KB
testcase_47 AC 510 ms
38,052 KB
testcase_48 AC 492 ms
38,052 KB
testcase_49 AC 510 ms
38,052 KB
testcase_50 AC 509 ms
38,052 KB
testcase_51 AC 501 ms
38,052 KB
testcase_52 AC 411 ms
29,852 KB
testcase_53 AC 567 ms
37,116 KB
testcase_54 AC 31 ms
10,232 KB
testcase_55 AC 30 ms
10,232 KB
testcase_56 AC 30 ms
10,232 KB
testcase_57 AC 208 ms
19,252 KB
testcase_58 AC 312 ms
24,320 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