結果

問題 No.3627 Share the Median
コンテスト
ユーザー 👑 loop0919
提出日時 2026-06-11 02:11:00
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
RE  
実行時間 -
コード長 1,607 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 478 ms
コンパイル使用メモリ 21,408 KB
実行使用メモリ 20,712 KB
平均クエリ数 1.00
最終ジャッジ日時 2026-08-14 20:51:52
合計ジャッジ時間 21,939 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
Sample 0 %
Easy 20 % RE * 16
Hard 80 % RE * 24
合計 3 * 0% = 0 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys


def read_line():
    line = sys.stdin.readline()
    if not line:
        sys.exit(0)
    return line


def read_ints_exact(length):
    vals = []
    while len(vals) < length:
        vals.extend(map(int, read_line().split()))
    return vals[:length]


def share_index(idx):
    print(f"share {idx}", flush=True)

    v = int(read_line())
    if v == -1:
        sys.exit(0)
    return v


def answer_and_continue(ans):
    print(f"answer {ans}", flush=True)

    r = int(read_line())
    if r == -1:
        sys.exit(0)


def main():
    T, Q = map(int, read_line().split())
    player = read_line().strip()

    is_alice = player == "Alice"

    for _ in range(T):
        N, M = map(int, read_line().split())

        my_len = N if is_alice else M
        other_len = M if is_alice else N

        my = read_ints_exact(my_len)
        other = []

        rounds = max(N, M)

        for r in range(1, rounds + 1):
            if r <= my_len:
                send_idx = r
            else:
                # 自分の列をすべて送り終えた後は、適当な有効 index を送る。
                send_idx = 1

            received = share_index(send_idx)

            # r 回目に相手は r 番目を送っている。
            # r > other_len のときは、相手もダミーを送っているだけなので無視する。
            if r <= other_len:
                other.append(received)

        all_values = my + other
        all_values.sort()

        median = all_values[(N + M) // 2]

        answer_and_continue(median)


if __name__ == "__main__":
    main()
0