提出 #37267840
ソースコード 拡げる
def I():return int(input())
def MAP():return map(int,input().split())
def MAPs():return map(str,input().split())
def LI(): return list(map(int,input().split()))
def TPL(): return tuple(map(int,input().split()))
def S():return input()
from collections import defaultdict,Counter,deque
from copy import deepcopy
from heapq import heapify,heappop,heappush
from bisect import bisect_left,bisect_right
from itertools import accumulate,product,permutations,combinations,combinations_with_replacement
from math import gcd,ceil,floor,factorial,sqrt,pi,sin,cos,tan,radians,exp
from functools import lru_cache
import time
import random
inf=float('inf');mod=998244353;Mod=10**9+7
dydx=[(1,0),(0,1),(-1,0),(0,-1)]
n=I()
a=LI();a.append(-10**18);a.append(10**18)
b=LI();b.append(-10**18);b.append(10**18)
c=LI();c.append(-10**18);c.append(10**18)
d=LI();d.append(-10**18);d.append(10**18)
import math
from bisect import bisect_left, bisect_right
from typing import Generic, Iterable, Iterator, TypeVar, Union, List
T = TypeVar('T')
class SortedSet(Generic[T]):
BUCKET_RATIO = 50
REBUILD_RATIO = 170
def _build(self, a=None) -> None:
"Evenly divide `a` into buckets."
if a is None: a = list(self)
size = self.size = len(a)
bucket_size = int(math.ceil(math.sqrt(size / self.BUCKET_RATIO)))
self.a = [a[size * i // bucket_size : size * (i + 1) // bucket_size] for i in range(bucket_size)]
def __init__(self, a: Iterable[T] = []) -> None:
"Make a new SortedSet from iterable. / O(N) if sorted and unique / O(N log N)"
a = list(a)
if not all(a[i] < a[i + 1] for i in range(len(a) - 1)):
a = sorted(set(a))
self._build(a)
def __iter__(self) -> Iterator[T]:
for i in self.a:
for j in i: yield j
def __reversed__(self) -> Iterator[T]:
for i in reversed(self.a):
for j in reversed(i): yield j
def __len__(self) -> int:
return self.size
def __repr__(self) -> str:
return "SortedSet" + str(self.a)
def __str__(self) -> str:
s = str(list(self))
return "{" + s[1 : len(s) - 1] + "}"
def _find_bucket(self, x: T) -> List[T]:
"Find the bucket which should contain x. self must not be empty."
for a in self.a:
if x <= a[-1]: return a
return a
def __contains__(self, x: T) -> bool:
if self.size == 0: return False
a = self._find_bucket(x)
i = bisect_left(a, x)
return i != len(a) and a[i] == x
def add(self, x: T) -> bool:
"Add an element and return True if added. / O(√N)"
if self.size == 0:
self.a = [[x]]
self.size = 1
return True
a = self._find_bucket(x)
i = bisect_left(a, x)
if i != len(a) and a[i] == x: return False
a.insert(i, x)
self.size += 1
if len(a) > len(self.a) * self.REBUILD_RATIO:
self._build()
return True
def discard(self, x: T) -> bool:
"Remove an element and return True if removed. / O(√N)"
if self.size == 0: return False
a = self._find_bucket(x)
i = bisect_left(a, x)
if i == len(a) or a[i] != x: return False
a.pop(i)
self.size -= 1
if len(a) == 0: self._build()
return True
def lt(self, x: T) -> Union[T, None]:
"Find the largest element < x, or None if it doesn't exist."
for a in reversed(self.a):
if a[0] < x:
return a[bisect_left(a, x) - 1]
def le(self, x: T) -> Union[T, None]:
"Find the largest element <= x, or None if it doesn't exist."
for a in reversed(self.a):
if a[0] <= x:
return a[bisect_right(a, x) - 1]
def gt(self, x: T) -> Union[T, None]:
"Find the smallest element > x, or None if it doesn't exist."
for a in self.a:
if a[-1] > x:
return a[bisect_right(a, x)]
def ge(self, x: T) -> Union[T, None]:
"Find the smallest element >= x, or None if it doesn't exist."
for a in self.a:
if a[-1] >= x:
return a[bisect_left(a, x)]
def __getitem__(self, x: int) -> T:
"Return the x-th element, or IndexError if it doesn't exist."
if x < 0: x += self.size
if x < 0: raise IndexError
for a in self.a:
if x < len(a): return a[x]
x -= len(a)
raise IndexError
def index(self, x: T) -> int:
"Count the number of elements < x."
ans = 0
for a in self.a:
if a[-1] >= x:
return ans + bisect_left(a, x)
ans += len(a)
return ans
def index_right(self, x: T) -> int:
"Count the number of elements <= x."
ans = 0
for a in self.a:
if a[-1] > x:
return ans + bisect_right(a, x)
ans += len(a)
return ans
B=SortedSet(b);C=SortedSet(c);D=SortedSet(d)
ans=inf
for i in range(n):
l=[a[i]]
if a[i]-B.le(a[i])>B.ge(a[i])-a[i]:
l.append(B.ge(a[i]))
else:
l.append(B.le(a[i]))
if a[i]-C.le(a[i])>C.ge(a[i])-a[i]:
l.append(C.ge(a[i]))
else:
l.append(C.le(a[i]))
if a[i]-D.le(a[i])>D.ge(a[i])-a[i]:
l.append(D.ge(a[i]))
else:
l.append(D.le(a[i]))
l.sort()
ans=min(ans,l[-1]-l[0])
print(ans)
提出情報
| 提出日時 | |
|---|---|
| 問題 | B - ジョイ四人組 (JOI04) |
| ユーザ | Dr_pilot |
| 言語 | PyPy3 (7.3.0) |
| 得点 | 7 |
| コード長 | 5655 Byte |
| 結果 | WA |
| 実行時間 | 704 ms |
| メモリ | 134780 KiB |
ジャッジ結果
| セット名 | Sample | Subtask1 | Subtask2 | Subtask3 | Subtask4 | Subtask5 | Subtask6 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 7 / 7 | 0 / 23 | 0 / 14 | 0 / 20 | 0 / 13 | 0 / 23 | ||||||||||||||||||||||||
| 結果 |
|
|
|
|
|
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt |
| Subtask1 | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, sample-01.txt |
| Subtask2 | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt |
| Subtask3 | 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, 03-08.txt, 03-09.txt, 03-10.txt, 03-11.txt, 03-12.txt, 03-13.txt, 03-14.txt, sample-02.txt, sample-03.txt, 02-06.txt |
| Subtask4 | 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, 03-08.txt, 03-09.txt, 03-10.txt, 03-11.txt, 03-12.txt, 03-13.txt, 03-14.txt, 04-01.txt, 04-02.txt, 04-03.txt, 04-04.txt, 04-05.txt, 04-06.txt, 04-07.txt, 04-08.txt, 04-09.txt, 04-10.txt, 04-11.txt, 04-12.txt, 04-13.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, 02-06.txt |
| Subtask5 | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, 03-08.txt, 03-09.txt, 03-10.txt, 03-11.txt, 03-12.txt, 03-13.txt, 03-14.txt, 04-01.txt, 04-02.txt, 04-03.txt, 04-04.txt, 04-05.txt, 04-06.txt, 04-07.txt, 04-08.txt, 04-09.txt, 04-10.txt, 04-11.txt, 04-12.txt, 04-13.txt, 05-01.txt, 05-02.txt, 05-03.txt, 05-04.txt, 05-05.txt, 05-06.txt, 05-07.txt, 05-08.txt, 05-09.txt, 05-10.txt, 05-11.txt, 05-12.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt |
| Subtask6 | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, 03-08.txt, 03-09.txt, 03-10.txt, 03-11.txt, 03-12.txt, 03-13.txt, 03-14.txt, 04-01.txt, 04-02.txt, 04-03.txt, 04-04.txt, 04-05.txt, 04-06.txt, 04-07.txt, 04-08.txt, 04-09.txt, 04-10.txt, 04-11.txt, 04-12.txt, 04-13.txt, 05-01.txt, 05-02.txt, 05-03.txt, 05-04.txt, 05-05.txt, 05-06.txt, 05-07.txt, 05-08.txt, 05-09.txt, 05-10.txt, 05-11.txt, 05-12.txt, 06-01.txt, 06-02.txt, 06-03.txt, 06-04.txt, 06-05.txt, 06-06.txt, 06-07.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 01-01.txt | AC | 134 ms | 83196 KiB |
| 01-02.txt | AC | 117 ms | 83188 KiB |
| 01-03.txt | AC | 118 ms | 83116 KiB |
| 01-04.txt | AC | 119 ms | 83164 KiB |
| 01-05.txt | AC | 121 ms | 83160 KiB |
| 02-01.txt | WA | 119 ms | 83136 KiB |
| 02-02.txt | AC | 118 ms | 83152 KiB |
| 02-03.txt | WA | 120 ms | 83240 KiB |
| 02-04.txt | WA | 121 ms | 83252 KiB |
| 02-05.txt | AC | 124 ms | 83060 KiB |
| 02-06.txt | WA | 118 ms | 83152 KiB |
| 03-01.txt | AC | 150 ms | 84452 KiB |
| 03-02.txt | AC | 154 ms | 84980 KiB |
| 03-03.txt | AC | 146 ms | 84000 KiB |
| 03-04.txt | AC | 152 ms | 84404 KiB |
| 03-05.txt | AC | 148 ms | 84492 KiB |
| 03-06.txt | AC | 148 ms | 84436 KiB |
| 03-07.txt | AC | 152 ms | 84640 KiB |
| 03-08.txt | AC | 152 ms | 85504 KiB |
| 03-09.txt | AC | 152 ms | 84584 KiB |
| 03-10.txt | AC | 154 ms | 84548 KiB |
| 03-11.txt | AC | 144 ms | 84200 KiB |
| 03-12.txt | AC | 148 ms | 84440 KiB |
| 03-13.txt | WA | 151 ms | 84344 KiB |
| 03-14.txt | AC | 145 ms | 84040 KiB |
| 04-01.txt | AC | 178 ms | 85256 KiB |
| 04-02.txt | AC | 154 ms | 84872 KiB |
| 04-03.txt | WA | 150 ms | 84804 KiB |
| 04-04.txt | AC | 154 ms | 84192 KiB |
| 04-05.txt | AC | 182 ms | 85204 KiB |
| 04-06.txt | AC | 186 ms | 86516 KiB |
| 04-07.txt | AC | 168 ms | 85256 KiB |
| 04-08.txt | AC | 195 ms | 88364 KiB |
| 04-09.txt | AC | 180 ms | 86148 KiB |
| 04-10.txt | AC | 148 ms | 84640 KiB |
| 04-11.txt | WA | 148 ms | 84708 KiB |
| 04-12.txt | WA | 178 ms | 85140 KiB |
| 04-13.txt | AC | 145 ms | 84480 KiB |
| 05-01.txt | AC | 165 ms | 85120 KiB |
| 05-02.txt | AC | 165 ms | 85000 KiB |
| 05-03.txt | AC | 176 ms | 85540 KiB |
| 05-04.txt | AC | 144 ms | 84516 KiB |
| 05-05.txt | AC | 154 ms | 84572 KiB |
| 05-06.txt | AC | 148 ms | 84716 KiB |
| 05-07.txt | WA | 173 ms | 85152 KiB |
| 05-08.txt | AC | 175 ms | 85192 KiB |
| 05-09.txt | AC | 175 ms | 85300 KiB |
| 05-10.txt | WA | 172 ms | 85556 KiB |
| 05-11.txt | WA | 178 ms | 85120 KiB |
| 05-12.txt | AC | 177 ms | 85188 KiB |
| 06-01.txt | AC | 594 ms | 124364 KiB |
| 06-02.txt | AC | 704 ms | 115064 KiB |
| 06-03.txt | WA | 429 ms | 124680 KiB |
| 06-04.txt | WA | 410 ms | 124104 KiB |
| 06-05.txt | AC | 499 ms | 134780 KiB |
| 06-06.txt | WA | 667 ms | 110736 KiB |
| 06-07.txt | AC | 575 ms | 121856 KiB |
| sample-01.txt | AC | 119 ms | 83320 KiB |
| sample-02.txt | AC | 118 ms | 83092 KiB |
| sample-03.txt | AC | 124 ms | 83068 KiB |
| sample-04.txt | AC | 119 ms | 83128 KiB |
| sample-05.txt | AC | 119 ms | 83276 KiB |