結果
問題 | No.808 Kaiten Sushi? |
ユーザー | mkawa2 |
提出日時 | 2022-03-03 12:21:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 896 ms / 2,000 ms |
コード長 | 3,886 bytes |
コンパイル時間 | 174 ms |
コンパイル使用メモリ | 82,392 KB |
実行使用メモリ | 253,032 KB |
最終ジャッジ日時 | 2024-07-17 08:50:00 |
合計ジャッジ時間 | 20,477 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,868 KB |
testcase_01 | AC | 41 ms
53,200 KB |
testcase_02 | AC | 38 ms
53,788 KB |
testcase_03 | AC | 39 ms
53,192 KB |
testcase_04 | AC | 38 ms
54,024 KB |
testcase_05 | AC | 39 ms
54,416 KB |
testcase_06 | AC | 39 ms
54,128 KB |
testcase_07 | AC | 110 ms
78,048 KB |
testcase_08 | AC | 111 ms
77,976 KB |
testcase_09 | AC | 145 ms
79,936 KB |
testcase_10 | AC | 127 ms
79,124 KB |
testcase_11 | AC | 111 ms
78,168 KB |
testcase_12 | AC | 125 ms
78,188 KB |
testcase_13 | AC | 112 ms
78,084 KB |
testcase_14 | AC | 66 ms
72,656 KB |
testcase_15 | AC | 134 ms
79,384 KB |
testcase_16 | AC | 122 ms
79,276 KB |
testcase_17 | AC | 78 ms
76,528 KB |
testcase_18 | AC | 61 ms
70,664 KB |
testcase_19 | AC | 51 ms
64,708 KB |
testcase_20 | AC | 60 ms
69,644 KB |
testcase_21 | AC | 52 ms
65,116 KB |
testcase_22 | AC | 60 ms
69,232 KB |
testcase_23 | AC | 314 ms
119,288 KB |
testcase_24 | AC | 271 ms
115,396 KB |
testcase_25 | AC | 285 ms
110,144 KB |
testcase_26 | AC | 287 ms
109,268 KB |
testcase_27 | AC | 685 ms
219,872 KB |
testcase_28 | AC | 287 ms
107,788 KB |
testcase_29 | AC | 671 ms
205,012 KB |
testcase_30 | AC | 457 ms
138,328 KB |
testcase_31 | AC | 742 ms
222,496 KB |
testcase_32 | AC | 760 ms
251,852 KB |
testcase_33 | AC | 451 ms
138,384 KB |
testcase_34 | AC | 495 ms
153,268 KB |
testcase_35 | AC | 587 ms
183,688 KB |
testcase_36 | AC | 436 ms
137,596 KB |
testcase_37 | AC | 40 ms
53,836 KB |
testcase_38 | AC | 39 ms
54,404 KB |
testcase_39 | AC | 778 ms
233,720 KB |
testcase_40 | AC | 266 ms
103,412 KB |
testcase_41 | AC | 278 ms
106,980 KB |
testcase_42 | AC | 685 ms
204,048 KB |
testcase_43 | AC | 300 ms
109,480 KB |
testcase_44 | AC | 474 ms
152,868 KB |
testcase_45 | AC | 312 ms
109,276 KB |
testcase_46 | AC | 235 ms
101,808 KB |
testcase_47 | AC | 854 ms
253,032 KB |
testcase_48 | AC | 867 ms
253,024 KB |
testcase_49 | AC | 874 ms
252,820 KB |
testcase_50 | AC | 896 ms
252,820 KB |
testcase_51 | AC | 847 ms
252,552 KB |
testcase_52 | AC | 469 ms
183,656 KB |
testcase_53 | AC | 634 ms
251,624 KB |
testcase_54 | AC | 38 ms
53,568 KB |
testcase_55 | AC | 38 ms
53,488 KB |
testcase_56 | AC | 39 ms
53,896 KB |
testcase_57 | AC | 264 ms
120,260 KB |
testcase_58 | AC | 390 ms
143,896 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 md = 10**9+7 # md = 998244353 class BitSum: def __init__(self, n): self.n = n+1 self.table = [0]*self.n def add(self, i, x): i += 1 while i < self.n: self.table[i] += x i += i & -i def sum(self, i): i += 1 res = 0 while i > 0: res += self.table[i] i -= i & -i return res def pos(self, x): idx = 0 for lv in range((self.n-1).bit_length()-1, -1, -1): mid = idx+(1 << lv) if mid >= self.n: continue if self.table[mid] < x: x -= self.table[mid] idx += 1 << lv return idx # 要素を先読みする代わりに、[0,10**6]でなくとも使える class Cset: def __init__(self, aa): aa = set(aa) self.dec = tuple(sorted(aa)) self.enc = {a: i for i, a in enumerate(self.dec)} self.mx = len(self.dec) self.size = 0 self.bit = BitSum(self.mx+1) self.nums = [False]*(self.mx+1) def __repr__(self): return "["+" ".join(str(self[i]) for i in range(self.size))+"]" def insert(self, a): if a not in self.enc: return False a = self.enc[a] if a < 0 or a > self.mx or self.nums[a]: return False self.size += 1 self.bit.add(a, 1) self.nums[a] = True return True def remove(self, value): if value not in self.enc: return False value = self.enc[value] if value < 0 or value > self.mx or not self.nums[value]: return False self.size -= 1 self.bit.add(value, -1) self.nums[value] = False return True def erase(self, index): i = index if i >= self.size or i < -self.size: return False if i < 0: i = self.size+i+1 else: i += 1 a = self.bit.pos(i) self.size -= 1 self.bit.add(a, -1) self.nums[a] = False return True def __getitem__(self, i): if i >= self.size or i < -self.size: return -1 if i < 0: i = self.size+i+1 else: i += 1 return self.dec[self.bit.pos(i)] def __contains__(self, item): return self.nums[self.enc[item]] def __len__(self): return self.size def bisect_left(self, a): if a not in self.enc: return -1 a = self.enc[a] if a < 0 or a > self.mx: return -1 if a == 0: return 0 return self.bit.sum(a-1) def bisect_right(self, a): if a not in self.enc: return -1 a = self.enc[a] if a < 0 or a > self.mx: return -1 return self.bit.sum(a) n, l = LI() xx0 = LI() yy0 = LI() ans = now = xx0[0] xx = Cset(xx0+yy0) yy = Cset(xx0+yy0) for x in xx0[1:]: xx.insert(x) for y in yy0: yy.insert(y) for _ in range(n-1): j = yy.bisect_left(now)%len(yy) # 一番近いお茶 i = xx.bisect_left(yy[j])%len(xx) # お茶後の寿司 x = xx[i] j = (yy.bisect_left(x)-1)%len(yy) # 次の寿司直前のお茶 y = yy[j] ans += (y-now)%l+(x-y)%l xx.remove(x) yy.remove(y) now = x # pDB(y, x, ans, xx, yy) ans += (yy[0]-now)%l print(ans)