結果

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

ソースコード

diff #
raw source code

#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <memory>
#include <vector>

namespace {

constexpr std::size_t IO_BUFFER_SIZE = 1u << 20;

class FastInput {
    std::unique_ptr<unsigned char[]> buffer_ =
        std::make_unique<unsigned char[]>(IO_BUFFER_SIZE);
    std::size_t position_ = 0;
    std::size_t length_ = 0;

    int get_char() {
        if (position_ == length_) {
            length_ = std::fread(buffer_.get(), 1, IO_BUFFER_SIZE, stdin);
            position_ = 0;
            if (length_ == 0) return -1;
        }
        return buffer_[position_++];
    }

public:
    bool read_u32(std::uint32_t& value) {
        int c;
        do {
            c = get_char();
        } while (c >= 0 && c <= ' ');

        if (c < '0' || c > '9') return false;
        std::uint32_t x = 0;
        do {
            x = x * 10u + static_cast<unsigned>(c - '0');
            c = get_char();
        } while (c >= '0' && c <= '9');
        value = x;
        return true;
    }
};

class FastOutput {
    std::unique_ptr<char[]> buffer_ =
        std::make_unique<char[]>(IO_BUFFER_SIZE);
    std::size_t position_ = 0;

public:
    ~FastOutput() { flush(); }

    void flush() {
        if (position_ != 0) {
            std::fwrite(buffer_.get(), 1, position_, stdout);
            position_ = 0;
        }
    }

    void write_u32(std::uint32_t x) {
        char digits[10];
        int length = 0;
        do {
            digits[length++] = static_cast<char>('0' + x % 10u);
            x /= 10u;
        } while (x != 0);

        if (position_ + static_cast<std::size_t>(length) + 1 > IO_BUFFER_SIZE) {
            flush();
        }
        while (length != 0) buffer_[position_++] = digits[--length];
        buffer_[position_++] = '\n';
    }
};

}  // namespace

int main() {
    FastInput input;
    std::uint32_t H, W;
    if (!input.read_u32(H) || !input.read_u32(W)) return 1;

    std::vector<std::uint32_t> row_sum(H);
    std::uint32_t total = 0;

    for (std::uint32_t i = 0; i < H; ++i) {
        std::uint32_t sum = 0;
        for (std::uint32_t j = 0; j < W; ++j) {
            std::uint32_t x;
            if (!input.read_u32(x)) return 1;
            sum += x;
        }
        row_sum[i] = sum;
        total += sum;
    }

    FastOutput output;
    for (std::uint32_t sum : row_sum) {
        output.write_u32(sum + total);
    }
}
0