結果

問題 No.3677 Global Checksum
コンテスト
ユーザー 👑 みうね
提出日時 2026-09-05 11:56:15
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 56 ms / 200 ms
+ 773µs
コード長 2,893 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 195 ms
コンパイル使用メモリ 48,800 KB
実行使用メモリ 9,732 KB
最終ジャッジ日時 2026-09-05 14:30:51
合計ジャッジ時間 12,977 ms
ジャッジサーバーID
(参考情報)
judge7_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <cstdint>
#include <cstring>

using uint = uint32_t;

struct FastScanner {
    static constexpr size_t SZ = 1 << 20;

    char buf[SZ + 32];
    size_t l = 0, r = 0;

    inline void load() {
        if (l != 0) {
            std::memmove(buf, buf + l, r - l);
            r -= l;
            l = 0;
        }

        r += std::fread(buf + r, 1, SZ - r, stdin);

        // EOF 付近でも数字列を安全に終了させるための番兵
        std::memset(buf + r, '\n', 16);
    }

    inline uint read_uint() {
        // uint32 の入力は高々10桁程度なので、
        // ここで一度だけ十分な残量を確保する。
        if (r - l < 16) {
            load();
        }

        while (buf[l] < '0') {
            ++l;
        }

        uint x = 0;
        while (buf[l] >= '0') {
            x = x * 10 + static_cast<uint>(buf[l] & 15);
            ++l;
        }

        return x;
    }
};

struct DigitTable {
    char d[10000][4];

    constexpr DigitTable() : d{} {
        for (int x = 0; x < 10000; ++x) {
            d[x][0] = '0' + x / 1000;
            d[x][1] = '0' + x / 100 % 10;
            d[x][2] = '0' + x / 10 % 10;
            d[x][3] = '0' + x % 10;
        }
    }
};

constexpr DigitTable digit_table;

struct FastPrinter {
    static constexpr size_t SZ = 1 << 20;

    char buf[SZ];
    size_t pos = 0;

    inline void flush() {
        std::fwrite(buf, 1, pos, stdout);
        pos = 0;
    }

    inline void ensure() {
        if (pos + 16 >= SZ) {
            flush();
        }
    }

    inline void write4(uint x) {
        std::memcpy(buf + pos, digit_table.d[x], 4);
        pos += 4;
    }

    inline void write_head(uint x) {
        const char *s = digit_table.d[x];

        if (x >= 1000) buf[pos++] = s[0];
        if (x >= 100) buf[pos++] = s[1];
        if (x >= 10) buf[pos++] = s[2];
        buf[pos++] = s[3];
    }

    inline void write_uint(uint x) {
        ensure();

        if (x >= 100000000) {
            uint a = x / 100000000;
            x -= a * 100000000;

            uint b = x / 10000;
            uint c = x - b * 10000;

            write_head(a);
            write4(b);
            write4(c);
        } else if (x >= 10000) {
            uint a = x / 10000;
            uint b = x - a * 10000;

            write_head(a);
            write4(b);
        } else {
            write_head(x);
        }

        buf[pos++] = '\n';
    }
};

static uint S[1000000];

int main() {
    FastScanner in;
    FastPrinter out;

    uint H = in.read_uint();
    uint W = in.read_uint();

    uint T = 0;

    for (uint i = 0; i < H; ++i) {
        uint s = 0;
        for (uint j = 0; j < W; ++j) {
            s += in.read_uint();
        }
        S[i] = s;
        T += s;
    }

    for (uint i = 0; i < H; ++i) {
        out.write_uint(S[i] + T);
    }

    out.flush();
}
0