結果

問題 No.2210 equence Squence Seuence
ユーザー タコイモタコイモ
提出日時 2023-02-11 10:01:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,500 ms / 2,000 ms
コード長 2,762 bytes
コンパイル時間 934 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 130,000 KB
最終ジャッジ日時 2023-09-22 08:48:09
合計ジャッジ時間 17,948 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
72,260 KB
testcase_01 AC 101 ms
72,472 KB
testcase_02 AC 102 ms
72,580 KB
testcase_03 AC 433 ms
90,312 KB
testcase_04 AC 432 ms
91,844 KB
testcase_05 AC 582 ms
97,240 KB
testcase_06 AC 551 ms
95,092 KB
testcase_07 AC 1,187 ms
118,824 KB
testcase_08 AC 105 ms
72,460 KB
testcase_09 AC 110 ms
77,148 KB
testcase_10 AC 111 ms
77,460 KB
testcase_11 AC 109 ms
77,008 KB
testcase_12 AC 112 ms
77,212 KB
testcase_13 AC 1,446 ms
128,564 KB
testcase_14 AC 1,464 ms
129,448 KB
testcase_15 AC 1,480 ms
130,000 KB
testcase_16 AC 1,465 ms
128,072 KB
testcase_17 AC 1,500 ms
128,572 KB
testcase_18 AC 104 ms
72,460 KB
testcase_19 AC 103 ms
72,612 KB
testcase_20 AC 102 ms
72,528 KB
testcase_21 AC 102 ms
72,452 KB
testcase_22 AC 104 ms
72,620 KB
testcase_23 AC 495 ms
114,928 KB
testcase_24 AC 397 ms
104,764 KB
testcase_25 AC 456 ms
110,856 KB
testcase_26 AC 566 ms
123,792 KB
testcase_27 AC 246 ms
92,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

base = 37
#mod = 2305843009213693951 #2**61 - 1 制限時間に余裕があり衝突したらこっちを使う
#これでTLEしたら
#mod2 = 10**9 + 7とかで複数でチェック
mod = 10**9 + 7
class RollingHash():
    def __init__(self, s, base, mod):
        self.mod = mod
        l = len(s)
        self.pw = pw = [1]*(l+1)

        
        self.h = h = [0]*(l+1)

        v = 0
        for i in range(l):
            #小文字のみ
            h[i+1] = v = (v * base + s[i]) % mod
            #大文字のみ or 大文字と小文字のみ
            #h[i+1] = v = (v * base + ord(s[i])-64) % mod
            #通常
            #h[i+1] = v = (v * base + ord(s[i])) % mod
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
    #[l,r)
    def get(self, l, r):
        return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod
import sys
#sys.setrecursionlimit(500000)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def TI(): return tuple(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip())
#for i, pi in enumerate(p):
from collections import defaultdict,deque
import bisect
import itertools
dic = defaultdict(int)
d = deque()

N,K = MI()
A = LI()
S = RollingHash(A,base,mod)
#https://aotamasaki.hatenablog.com/entry/meguru_bisect
#arg桁
def is_ok(arg,x,y):
  if arg == 0:
    return True
  if arg == N:
    return False
  if arg <= x and arg <= y:
    return True
  
  if arg <= x:
    X = S.get(0,arg)
  else:
    X = (S.get(0,x)*S.pw[arg-x]+S.get(x+1,arg+1))%mod
  if arg <= y:
    Y = S.get(0,arg)
  else:
    Y = (S.get(0,y)*S.pw[arg-y]+S.get(y+1,arg+1))%mod  
  
  if X == Y:
    return True
  else:
    return False
        
def meguru_bisect(ng, ok,s,t):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid,s,t):
            ok = mid
        else:
            ng = mid
    return ok
def cmp(x,y):
  h = meguru_bisect(N,0,x,y)
  
  if h == N-1:
    return 0
  
  if x > h:
    f = A[h]
  else:
    f = A[h+1]
  if y > h:
    ff = A[h]
  else:
    ff = A[h+1]
  if f < ff:
    return -1
  elif f == ff:
    return 0
  else:
    return 1
    
  
D = list(range(N))
from functools import cmp_to_key
p = sorted(D, key = cmp_to_key(cmp))
x = p[K - 1]

ans = A[:x] + A[x + 1:]

print(*ans)
0