結果

問題 No.2577 Simple Permutation Guess
ユーザー iseeisee
提出日時 2023-12-05 16:33:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,010 ms / 2,000 ms
コード長 5,258 bytes
コンパイル時間 1,345 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 98,044 KB
平均クエリ数 248.84
最終ジャッジ日時 2023-12-05 16:34:21
合計ジャッジ時間 49,896 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
83,868 KB
testcase_01 AC 809 ms
97,276 KB
testcase_02 AC 367 ms
95,336 KB
testcase_03 AC 93 ms
83,868 KB
testcase_04 AC 425 ms
95,660 KB
testcase_05 AC 515 ms
96,464 KB
testcase_06 AC 973 ms
97,584 KB
testcase_07 AC 1,010 ms
97,632 KB
testcase_08 AC 976 ms
97,972 KB
testcase_09 AC 973 ms
97,096 KB
testcase_10 AC 978 ms
97,460 KB
testcase_11 AC 92 ms
85,944 KB
testcase_12 AC 91 ms
83,868 KB
testcase_13 AC 136 ms
94,160 KB
testcase_14 AC 107 ms
89,028 KB
testcase_15 AC 92 ms
83,864 KB
testcase_16 AC 91 ms
83,868 KB
testcase_17 AC 125 ms
83,868 KB
testcase_18 AC 90 ms
83,868 KB
testcase_19 AC 89 ms
83,868 KB
testcase_20 AC 92 ms
83,868 KB
testcase_21 AC 89 ms
83,868 KB
testcase_22 AC 89 ms
83,860 KB
testcase_23 AC 89 ms
83,860 KB
testcase_24 AC 93 ms
83,860 KB
testcase_25 AC 92 ms
83,860 KB
testcase_26 AC 97 ms
83,860 KB
testcase_27 AC 97 ms
83,860 KB
testcase_28 AC 96 ms
83,860 KB
testcase_29 AC 92 ms
83,860 KB
testcase_30 AC 91 ms
83,860 KB
testcase_31 AC 95 ms
83,868 KB
testcase_32 AC 91 ms
83,868 KB
testcase_33 AC 93 ms
83,868 KB
testcase_34 AC 92 ms
83,868 KB
testcase_35 AC 105 ms
83,868 KB
testcase_36 AC 92 ms
83,868 KB
testcase_37 AC 89 ms
83,860 KB
testcase_38 AC 91 ms
83,860 KB
testcase_39 AC 90 ms
83,860 KB
testcase_40 AC 94 ms
83,860 KB
testcase_41 AC 91 ms
83,860 KB
testcase_42 AC 95 ms
83,856 KB
testcase_43 AC 92 ms
83,860 KB
testcase_44 AC 100 ms
83,860 KB
testcase_45 AC 95 ms
83,860 KB
testcase_46 AC 94 ms
83,860 KB
testcase_47 AC 95 ms
83,860 KB
testcase_48 AC 91 ms
83,860 KB
testcase_49 AC 90 ms
83,860 KB
testcase_50 AC 91 ms
83,860 KB
testcase_51 AC 89 ms
83,860 KB
testcase_52 AC 87 ms
83,860 KB
testcase_53 AC 101 ms
83,860 KB
testcase_54 AC 89 ms
83,860 KB
testcase_55 AC 91 ms
83,860 KB
testcase_56 AC 100 ms
83,860 KB
testcase_57 AC 93 ms
83,856 KB
testcase_58 AC 87 ms
83,860 KB
testcase_59 AC 90 ms
83,860 KB
testcase_60 AC 91 ms
83,860 KB
testcase_61 AC 93 ms
83,860 KB
testcase_62 AC 102 ms
83,860 KB
testcase_63 AC 93 ms
83,860 KB
testcase_64 AC 89 ms
83,860 KB
testcase_65 AC 90 ms
83,860 KB
testcase_66 AC 88 ms
83,860 KB
testcase_67 AC 92 ms
83,860 KB
testcase_68 AC 92 ms
83,860 KB
testcase_69 AC 94 ms
83,860 KB
testcase_70 AC 98 ms
83,860 KB
testcase_71 AC 102 ms
83,860 KB
testcase_72 AC 90 ms
83,860 KB
testcase_73 AC 88 ms
83,868 KB
testcase_74 AC 128 ms
93,896 KB
testcase_75 AC 128 ms
94,032 KB
testcase_76 AC 130 ms
93,908 KB
testcase_77 AC 129 ms
94,032 KB
testcase_78 AC 129 ms
93,776 KB
testcase_79 AC 128 ms
94,160 KB
testcase_80 AC 132 ms
94,156 KB
testcase_81 AC 138 ms
94,160 KB
testcase_82 AC 132 ms
94,160 KB
testcase_83 AC 133 ms
94,144 KB
testcase_84 AC 131 ms
94,160 KB
testcase_85 AC 154 ms
94,160 KB
testcase_86 AC 130 ms
94,160 KB
testcase_87 AC 130 ms
94,160 KB
testcase_88 AC 131 ms
94,160 KB
testcase_89 AC 132 ms
94,160 KB
testcase_90 AC 131 ms
94,160 KB
testcase_91 AC 143 ms
94,160 KB
testcase_92 AC 858 ms
97,388 KB
testcase_93 AC 779 ms
96,696 KB
testcase_94 AC 724 ms
96,564 KB
testcase_95 AC 945 ms
97,928 KB
testcase_96 AC 947 ms
97,040 KB
testcase_97 AC 916 ms
97,588 KB
testcase_98 AC 873 ms
96,992 KB
testcase_99 AC 940 ms
98,044 KB
testcase_100 AC 797 ms
96,860 KB
testcase_101 AC 915 ms
97,552 KB
evil_1_rnd_1.txt AC 1,647 ms
98,300 KB
evil_1_rnd_2.txt AC 1,659 ms
99,656 KB
evil_2_big_1.txt TLE -
evil_2_big_2.txt TLE -
evil_2_big_3.txt TLE -
evil_3_sorted_1.txt AC 1,105 ms
98,060 KB
evil_4_sorted_rev_1.txt AC 1,063 ms
98,180 KB
evil_4_sorted_rev_2.txt AC 1,401 ms
98,936 KB
evil_400_sorted.txt AC 1,644 ms
100,188 KB
evil_400_sorted_rev.txt TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

# https://github.com/tatyam-prime/SortedSet/blob/main/SortedSet.py
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

def main():
    # 入力
    N = int(input())
    # 計算・出力
    FACT = [0]*(N+1)
    FACT[0] = 1
    for i in range(1, N+1):
        FACT[i] = FACT[i-1] * i
    
    def getKthPermutation(K):
        res = []
        left = SortedSet(range(1, N+1))
        x = K
        for i in range(N):
            ni, x = divmod(x, FACT[N-i-1])
            res.append(left[ni])
            left.discard(res[-1])
        return res
    
    def ask(K):
        print('?', *getKthPermutation(K), flush=True)
        ret = int(input())
        return ret

    def ans(K):
        print('!', *getKthPermutation(K), flush=True)

    ng = FACT[N]
    ok = 0  # KP(ok) <= P
    while abs(ng-ok) > 1:
        mid = (ok+ng)//2
        ret = ask(mid)
        if ret == 1 : # ここ頑張る
            ok = mid
        elif ret == 0:
            ng = mid
        else:
            return
    ans(ok)

if __name__ == "__main__":
    main()
    # import math
    # for n in range(240, 251):
    #     M = math.floor(math.floor((n-1) * math.log2(n)) - (n-1)/2 + 1)
    #     print(n, M)
0