結果

問題 No.1830 Balanced Majority
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2022-02-04 22:21:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,779 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 87,756 KB
平均クエリ数 8.08
最終ジャッジ日時 2023-09-02 05:02:59
合計ジャッジ時間 4,478 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
87,124 KB
testcase_01 AC 94 ms
86,996 KB
testcase_02 AC 92 ms
87,296 KB
testcase_03 AC 94 ms
87,112 KB
testcase_04 AC 93 ms
87,136 KB
testcase_05 AC 90 ms
87,032 KB
testcase_06 WA -
testcase_07 AC 95 ms
87,332 KB
testcase_08 AC 98 ms
87,108 KB
testcase_09 AC 93 ms
87,140 KB
testcase_10 AC 94 ms
87,184 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 94 ms
87,224 KB
testcase_15 AC 93 ms
87,148 KB
testcase_16 AC 94 ms
87,492 KB
testcase_17 AC 93 ms
87,500 KB
testcase_18 AC 93 ms
87,608 KB
testcase_19 AC 92 ms
87,444 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/1830

前半と後半で分ける?
まず、0項目をAとする

ラストがBの場合、最初と最後を除いた区間が答え
ラストもAの場合は

真ん中で切る
左右のうち、Bが多いほうを角から二分探索。
A=Bとなる区間を見つける

補集合が答え


"""

import sys
from sys import stdin

N = int(stdin.readline())
askdic = {}
askdic[N] = N//2

def ask(i,side):

    if side == "L":
        if i in askdic:
            return askdic[i]
        print ("?",i,flush=True)
        cat = int(stdin.readline())
        askdic[i] = cat
        return askdic[i]

    else:
        askind = N-i
        if askind in askdic:
            return N//2 - askdic[askind]
        print ("?",askind,flush=True)
        cat = int(stdin.readline())
        askdic[askind] = cat
        return N//2 - askdic[askind]

def getAB(rangenum,askans):

    if l1 == 0:
        return askans , rangenum - askans
    else:
        return rangenum - askans, askans

#N = int(stdin.readline())

l1 = ask(1,"L")
r1 = ask(1,"R")

if l1 != r1:
    print ("!",2,N-1,flush=True)
    sys.exit()

else:

    leftA,leftB = getAB(N//2, ask(N//2,"L") )
    
    if leftA <= N//2:
        l = 1
        r = N//2
        while r-l != 1:
            m = (l+r)//2
            mA,mB = getAB(m , ask(m,"L") )
            if mA <= mB:
                r = m
            else:
                l = m

        print ("!",r+1,N,flush=True)
        sys.exit()

    else:
        l = 1
        r = N//2
        while r-l != 1:
            m = (l+r)//2
            mA,mB = getAB(m , ask(m,"R") )
            if mA <= mB:
                r = m
            else:
                l = m

        print ("!",1,N-r,flush=True)
        sys.exit()

    
0