結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー t33ft33f
提出日時 2021-02-20 09:44:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,811 ms / 3,153 ms
コード長 1,192 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 77,376 KB
実行使用メモリ 5,024 KB
最終ジャッジ日時 2023-10-17 13:31:13
合計ジャッジ時間 72,943 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2,768 ms
5,012 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2,784 ms
5,012 KB
testcase_09 AC 2,786 ms
5,012 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2,764 ms
5,016 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2,775 ms
5,020 KB
testcase_14 AC 2,798 ms
5,020 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2,781 ms
5,024 KB
testcase_17 AC 2,807 ms
5,024 KB
testcase_18 AC 2,787 ms
5,024 KB
testcase_19 AC 2,799 ms
5,024 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2,777 ms
5,024 KB
testcase_22 AC 2,777 ms
5,024 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2,783 ms
5,020 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2,811 ms
5,024 KB
testcase_27 AC 2,806 ms
5,024 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2,802 ms
5,024 KB
testcase_30 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int w, h, x; cin >> w >> h >> x;
    int a[3][3] = {{0, 0, 0},{0, 0, 0},{0, 0, 0}};
    int s = 0;
    for (int i = 0; i < 2; i++) {
        if (h % 3 == i) continue;
        for (int j = 0; j < 2; j++) {
            if (w % 3 == j) continue;
            a[i][j] = min(9, x-s);
            s += a[i][j];
        }
    }
    if (s != x) cout << -1 << endl;
    else {
        vector ans(h, vector<int>(w, 0));
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
                ans[i][j] = a[i%3][j%3];                
        for (int i = 0; i < h; i++) {
            for (int a : ans[i]) cout << a;
            cout << endl;
        }

        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++) {
                int sum = 0;
                for (int x = i-1; x <= i+1; x++)
                    for (int y = j-1; y <= j+1; y++)
                        if (0 <= x && x < h && 0 <= y && y < w)
                            sum += ans[x][y];
                cerr << i << ' ' << j << ' ' << sum << endl;
                assert(sum == x);
            }
    }
}
0