Submission #69508569


Source Code Expand

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

def solve(N,K,X,A):
    A.sort()
    A = [a<<30 for a in A]
    def cond(x):
        cnt = 0
        t = 1
        split_done = 0
        for a in A:
            if a < x:
                continue
            while a >= 2*t*x:
                t *= 2
            cnt += 1
            split_done += t - 1
        
        if split_done >= K:
            return cnt + K >= X
        else:
            return cnt + split_done >= X and (cnt + split_done - X) + split_done >= K
        
        return cnt + min(K,split_done) >= X and split_done + cnt - X >= K

    #print(cond(1))
    ok = 0
    ng = 1<<60
    for _ in range(60):
        mid = (ok+ng)//2
        if cond(mid):
            ok = mid
        else:
            ng = mid
    
    return ok/(1<<30)

def brute(N,K,X,A):
    A.sort()
    for _ in range(K):
        a = A.pop()
        A.append(a//2)
        A.append(a//2)
        A.sort()
    return A[::-1][X-1]

while False:
    N = random.randint(1,3)
    K = random.randint(1,3)
    X = random.randint(1,N+K)
    A = [random.randint(1,10)<<30 for i in range(N)]

    N,K,X = 3,1,3
    A = [2,1,9]

    exp = brute(N,K,X,A[:])
    res = solve(N,K,X,A[:])

    if exp!=res:
        print(N,K,X)
        print([a>>30 for a in A])
        print(exp,res)
        exit()
    else:
        print("AC",N,K,X)

for _ in range(int(input())):
    N,K,X = mi()
    A = li()
    print(solve(N,K,X,A))


Submission Info

Submission Time
Task E - Cut in Half
User chinerist
Language Python (PyPy 3.10-v7.3.12)
Score 475
Code Size 1760 Byte
Status AC
Exec Time 404 ms
Memory 100580 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 1
AC × 36
Set Name Test Cases
Sample sample_01.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, sample_01.txt
Case Name Status Exec Time Memory
random_01.txt AC 149 ms 100580 KiB
random_02.txt AC 125 ms 93252 KiB
random_03.txt AC 150 ms 100560 KiB
random_04.txt AC 128 ms 93408 KiB
random_05.txt AC 150 ms 100456 KiB
random_06.txt AC 135 ms 96588 KiB
random_07.txt AC 147 ms 100452 KiB
random_08.txt AC 139 ms 98148 KiB
random_09.txt AC 152 ms 85260 KiB
random_10.txt AC 128 ms 85028 KiB
random_11.txt AC 149 ms 84980 KiB
random_12.txt AC 127 ms 84756 KiB
random_13.txt AC 151 ms 84932 KiB
random_14.txt AC 127 ms 84968 KiB
random_15.txt AC 150 ms 85212 KiB
random_16.txt AC 127 ms 84984 KiB
random_17.txt AC 135 ms 100332 KiB
random_18.txt AC 109 ms 99768 KiB
random_19.txt AC 137 ms 100008 KiB
random_20.txt AC 136 ms 100328 KiB
random_21.txt AC 109 ms 99920 KiB
random_22.txt AC 134 ms 99968 KiB
random_23.txt AC 143 ms 100572 KiB
random_24.txt AC 141 ms 100568 KiB
random_25.txt AC 142 ms 100116 KiB
random_26.txt AC 142 ms 100304 KiB
random_27.txt AC 142 ms 100264 KiB
random_28.txt AC 140 ms 99752 KiB
random_29.txt AC 136 ms 100308 KiB
random_30.txt AC 136 ms 100316 KiB
random_31.txt AC 122 ms 100400 KiB
random_32.txt AC 87 ms 83180 KiB
random_33.txt AC 404 ms 90056 KiB
random_34.txt AC 386 ms 90316 KiB
random_35.txt AC 391 ms 89972 KiB
sample_01.txt AC 86 ms 83312 KiB