結果

問題 No.3677 Global Checksum
コンテスト
ユーザー harurun
提出日時 2026-09-05 01:49:16
言語 PyPy3
(7.3.23)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 5,161 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 219 ms
コンパイル使用メモリ 95,820 KB
実行使用メモリ 108,384 KB
最終ジャッジ日時 2026-09-05 01:49:21
合計ジャッジ時間 4,997 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 TLE * 1 -- * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
import pypyjit
from __pypy__ import builders

pypyjit.set_param(
    threshold=200,
    function_threshold=50,
    trace_eagerness=2,
)

MASK = 0xFFFFFFFF


def read_num(d, p):
    x = d[p] - 48
    p += 1

    c = d[p]
    p += 1
    if c < 48:
        return x, p
    x = x * 10 + c - 48

    c = d[p]
    p += 1
    if c < 48:
        return x, p
    x = x * 10 + c - 48

    c = d[p]
    p += 1
    if c < 48:
        return x, p
    x = x * 10 + c - 48

    c = d[p]
    p += 1
    if c < 48:
        return x, p
    x = x * 10 + c - 48

    c = d[p]
    p += 1
    if c < 48:
        return x, p
    x = x * 10 + c - 48

    c = d[p]
    p += 1
    if c < 48:
        return x, p
    x = x * 10 + c - 48

    c = d[p]
    p += 1
    if c < 48:
        return x, p
    x = x * 10 + c - 48

    c = d[p]
    p += 1
    if c < 48:
        return x, p
    x = x * 10 + c - 48

    c = d[p]
    p += 1
    if c < 48:
        return x, p

    # 10桁なら A_ij = 1000000000
    # 次の1文字は必ず区切り
    p += 1
    return 1000000000, p


# W が大きいケース用。
# read_num() の関数呼び出しを要素ごとに行わず、
# parser 自体を tight loop の中に置く。
def read_row(d, p, n):
    row = 0

    while n:
        x = d[p] - 48
        p += 1

        c = d[p]
        p += 1
        if c >= 48:
            x = x * 10 + c - 48

            c = d[p]
            p += 1
            if c >= 48:
                x = x * 10 + c - 48

                c = d[p]
                p += 1
                if c >= 48:
                    x = x * 10 + c - 48

                    c = d[p]
                    p += 1
                    if c >= 48:
                        x = x * 10 + c - 48

                        c = d[p]
                        p += 1
                        if c >= 48:
                            x = x * 10 + c - 48

                            c = d[p]
                            p += 1
                            if c >= 48:
                                x = x * 10 + c - 48

                                c = d[p]
                                p += 1
                                if c >= 48:
                                    x = x * 10 + c - 48

                                    c = d[p]
                                    p += 1
                                    if c >= 48:
                                        x = x * 10 + c - 48

                                        c = d[p]
                                        p += 1
                                        if c >= 48:
                                            # 10桁は 1000000000 のみ
                                            x = 1000000000

                                            # delimiter
                                            p += 1

        row += x
        n -= 1

    return row, p


def main():
    data = sys.stdin.buffer.read()
    p = 0

    # H
    H = 0
    while True:
        c = data[p]
        p += 1
        if c < 48:
            break
        H = H * 10 + c - 48

    # W
    W = 0
    while True:
        c = data[p]
        p += 1
        if c < 48:
            break
        W = W * 10 + c - 48

    if data[-1] >= 48:
        data += b'\n'

    rn = read_num

    # 横一列は専用ループで全て読む。
    # 最大 4,000,000 回の read_num() 呼び出しをなくす。
    if H == 1:
        total, p = read_row(data, p, W)
        sys.stdout.write(str((total << 1) & MASK))
        return

    S = [0] * H
    total = 0
    r = 0

    if W == 1:
        while r < H:
            a, p = rn(data, p)
            S[r] = a
            total += a
            r += 1

    elif W == 2:
        while r < H:
            a, p = rn(data, p)
            b, p = rn(data, p)

            row = a + b
            S[r] = row
            total += row
            r += 1

    elif W == 3:
        while r < H:
            a, p = rn(data, p)
            b, p = rn(data, p)
            c, p = rn(data, p)

            row = a + b + c
            S[r] = row
            total += row
            r += 1

    elif W == 4:
        while r < H:
            a, p = rn(data, p)
            b, p = rn(data, p)
            c, p = rn(data, p)
            d, p = rn(data, p)

            row = a + b + c + d
            S[r] = row
            total += row
            r += 1

    # 横長の場合。
    # H <= 62500 なので read_row の呼び出し回数も多くない。
    elif W >= 64:
        rr = read_row

        while r < H:
            row, p = rr(data, p, W)

            S[r] = row
            total += row
            r += 1

    # W=5..63 はAC版をそのまま残す
    else:
        while r < H:
            row = 0
            j = 0

            while j < W:
                x, p = rn(data, p)
                row += x
                j += 1

            S[r] = row
            total += row
            r += 1

    T = total & MASK

    # AC版の出力をそのまま維持
    out = builders.StringBuilder(H * 4)
    append = out.append

    for s in S:
        append(str((s + T) & MASK))
        append('\n')

    sys.stdout.write(out.build())


main()
0