結果

問題 No.3666 League of Jigsaw
コンテスト
ユーザー tyawanmusi
提出日時 2026-08-22 17:08:18
言語 PyPy3
(7.3.23)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 387 ms / 2,000 ms
+ 171µs
コード長 5,506 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 268 ms
コンパイル使用メモリ 96,112 KB
実行使用メモリ 95,488 KB
最終ジャッジ日時 2026-08-30 13:03:25
合計ジャッジ時間 3,647 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

"""
厳密入力パーサー
競技プログラミングの入力を想定

- read_space():
    1文字以上の SPACE/TAB を要求して消費
- read_eoln():
    行末改行を要求して消費
- read_eof():
    EOF を要求
- read_int(lo=None, hi=None):
    1トークンを10進整数として読む(負数可/範囲チェック有)
- read_string(min_len=None, max_len=None):
    1トークンを文字列として読む(長さチェック有)

使用例:
ins = StrictIn.from_stdin_ascii()
N = ins.read_int(lo=1, hi=200000)
ins.read_eoln()
S = ins.read_string(min_len=N, max_len=N)
ins.read_eoln()
A = []
for i in range(N):
    x = ins.read_int(lo=-200000, hi=200000)
    A.append(x)
    if i != N-1:
        ins.read_space()
ins.read_eoln()
ins.read_eof()
"""

import sys

class InputError(Exception):
    pass

class StrictIn:

    def __init__(self, s: bytes, i: int = 0, line: int = 1, col: int = 1):
        self.s = s
        self.i = i
        self.line = line
        self.col = col

    @staticmethod
    def from_stdin_ascii() -> "StrictIn":
        raw = sys.stdin.buffer.read()
        for p, b in enumerate(raw):
            if b >= 0x80:
                raise InputError(f"non-ASCII byte at offset {p}: 0x{b:02x}")
            if b in (0x09, 0x0A, 0x0D):
                continue
            if 0x20 <= b <= 0x7E:
                continue
            raise InputError(f"disallowed control byte at offset {p}: 0x{b:02x}")
        return StrictIn(raw)

    def _eof(self) -> bool:
        return self.i >= len(self.s)

    def _peek(self):
        return None if self._eof() else self.s[self.i]

    def _advance(self) -> int:
        if self._eof():
            self._err("unexpected EOF")
        b = self.s[self.i]
        self.i += 1
        if b == 0x0A:
            self.line += 1
            self.col = 1
        else:
            self.col += 1
        return b

    def _err(self, msg: str) -> None:
        raise InputError(f"{msg} (line {self.line}, col {self.col})")

    def _consume_newline(self) -> None:
        b = self._peek()
        if b == 0x0A:
            self._advance()
            return
        if b == 0x0D:
            self._advance()
            if self._peek() != 0x0A:
                self._err("bare CR is not allowed (use LF or CRLF)")
            self._advance()
            self.line += 1
            self.col = 1
            return
        self._err("expected EOL")

    def skip_spaces(self) -> None:
        while (not self._eof()) and (self._peek() in (0x20, 0x09)):
            self._advance()

    def skip_ws(self) -> None:
        while not self._eof():
            b = self._peek()
            if b in (0x20, 0x09):
                self._advance()
            elif b in (0x0A, 0x0D):
                self._consume_newline()
            else:
                break

    def read_space(self) -> None:
        b = self._peek()
        if b not in (0x20, 0x09):
            self._err("expected SPACE/TAB")
        while (not self._eof()) and (self._peek() in (0x20, 0x09)):
            self._advance()

    def read_eoln(self) -> None:
        self._consume_newline()

    def read_eof(self) -> None:
        if not self._eof():
            self._err("expected EOF (extra data exists)")

    def read_token(self) -> str:
        b = self._peek()
        if b is None:
            self._err(f"unexpected EOF while reading token")
        if b in (0x20, 0x09):
            self._err(f"unexpected leading SPACE/TAB while reading token")
        if b in (0x0A, 0x0D):
            self._err(f"unexpected EOL while reading token")

        start = self.i
        while not self._eof():
            b = self._peek()
            if b in (0x20, 0x09, 0x0A, 0x0D):
                break
            self._advance()
        return self.s[start:self.i].decode("ascii")

    def read_int(self, lo=None, hi=None) -> int:
        t_str = self.read_token()
        t = t_str.encode("ascii")

        if t[:1] == b"-":
            body = t[1:]
            if len(body) == 0:
                self._err(f"int is not an integer")
        else:
            body = t

        if len(body) == 0 or (not all(48 <= c <= 57 for c in body)):
            self._err(f"int is not a base-10 integer")

        x = int(t_str)
        if lo is not None and x < lo:
            self._err(f"int out of range: {x} < {lo}")
        if hi is not None and x > hi:
            self._err(f"int out of range: {x} > {hi}")
        return x

    def read_string(self, min_len: int | None = None, max_len: int | None = None) -> str:

        s = self.read_token()

        if min_len is not None and len(s) < min_len:
            self._err(f"str too short: len={len(s)} < {min_len}")
        if max_len is not None and len(s) > max_len:
            self._err(f"str too long: len={len(s)} > {max_len}")

        return s

ins = StrictIn.from_stdin_ascii()
t = ins.read_int(lo=1, hi=2*10**5)
ins.read_eoln()
for _ in range(t):
    l = ins.read_int(lo=0, hi=10**9)
    ins.read_space()
    j = ins.read_int(lo=0, hi=10**9)
    ins.read_space()
    o = ins.read_int(lo=0, hi=10**9)
    ins.read_eoln()
    assert (l + j + o) % 3 == 0
    if (l + j - 2 * o) % 6 != 0:
        print("No")
        continue
    k = (l + j - 2 * o) // 6
    if k < 0:
        print("No")
        continue
    if k <= l <= 5 * k + 2 * o:
        if o == 0:
            if l % 2 + j % 2 != 0:
                print("No")
                continue
        print("Yes")
    else:
        print("No")
ins.read_eof()
0