結果

問題 No.3734 No Flat Notes
コンテスト
ユーザー 👑 kencho
提出日時 2026-07-08 19:50:02
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,501 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,144 ms
コンパイル使用メモリ 358,328 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-19 12:32:08
合計ジャッジ時間 6,321 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
部分点 20 % AC * 28
満点 80 % AC * 34 WA * 26
合計 3.5 * 20% = 70 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

vector<pair<int, int>> buildCells(int h, int w) {
    vector<pair<int, int>> cells;
    cells.reserve(h * w);
    for (int row = 0; row < h; row++) {
        if (row % 2 == 0) {
            for (int col = 0; col < w; col++) {
                cells.push_back({row, col});
            }
        } else {
            for (int col = w - 1; col >= 0; col--) {
                cells.push_back({row, col});
            }
        }
    }
    return cells;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int h;
    int w;
    int m;
    cin >> h >> w >> m;

    if (h % 2 != 0 || w % 2 != 0 || m == 0) {
        cout << -1 << '\n';
        return 0;
    }

    int total = h * w;
    int k = m - 1;
    int low = 1;
    int high = total;
    int middle = k + 1;
    vector<vector<int>> grid(h, vector<int>(w));
    vector<pair<int, int>> cells = buildCells(h, w);

    for (int t = 1; t <= total; t++) {
        auto [row, col] = cells[t - 1];
        if (t <= 2 * k) {
            if (t % 2 == 1) {
                grid[row][col] = low++;
            } else {
                grid[row][col] = high--;
            }
        } else {
            grid[row][col] = middle++;
        }
    }

    for (int row = 0; row < h; row++) {
        for (int col = 0; col < w; col++) {
            if (col > 0) {
                cout << ' ';
            }
            cout << grid[row][col];
        }
        cout << '\n';
    }

    return 0;
}
0