結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー se1ka2se1ka2
提出日時 2021-02-19 21:41:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 3,153 ms
コード長 1,436 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 65,568 KB
実行使用メモリ 4,496 KB
最終ジャッジ日時 2023-10-15 00:28:21
合計ジャッジ時間 26,387 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 20 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 21 ms
4,372 KB
testcase_09 AC 21 ms
4,368 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 21 ms
4,368 KB
testcase_12 AC 1 ms
4,372 KB
testcase_13 AC 21 ms
4,372 KB
testcase_14 AC 21 ms
4,368 KB
testcase_15 AC 1 ms
4,372 KB
testcase_16 AC 21 ms
4,368 KB
testcase_17 AC 21 ms
4,368 KB
testcase_18 AC 21 ms
4,372 KB
testcase_19 AC 21 ms
4,368 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 21 ms
4,372 KB
testcase_22 AC 21 ms
4,372 KB
testcase_23 AC 2 ms
4,496 KB
testcase_24 AC 21 ms
4,368 KB
testcase_25 AC 2 ms
4,368 KB
testcase_26 AC 20 ms
4,368 KB
testcase_27 AC 21 ms
4,368 KB
testcase_28 AC 2 ms
4,372 KB
testcase_29 AC 21 ms
4,372 KB
testcase_30 AC 2 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int b[3][3];

int main()
{
    int w, h, x;
    cin >> w >> h >> x;
    if(h % 3 == 2 && w % 3 == 2){
        if(x > 36){
            cout << -1 << endl;
            return 0;
        }
        for(int i = 0; i < 2; i++){
            for(int j = 0; j < 2; j++){
                b[i][j] = min(9, x);
                x -= b[i][j];
            }
        }
    }
    else if(h % 3 == 2){
        if(x > 18){
            cout << -1 << endl;
            return 0;;
        }
        for(int i = 0; i < 2; i++){
            if(w % 3 == 1){
                b[i][0] = min(9, x);
                x -= b[i][0];
            }
            else{
                b[i][1] = min(9, x);
                x -= b[i][1];
            }
        }
    }
    else if(w % 3 == 2){
        if(x > 18){
            cout << -1 << endl;
            return 0;
        }
        for(int j = 0; j < 2; j++){
            if(h % 3 == 1){
                b[0][j] = min(9, x);
                x -= b[0][j];
            }
            else{
                b[1][j] = min(9, x);
                x -= b[1][j];
            }
        }
    }
    else{
        if(x > 9){
            cout << -1 << endl;
            return 0;
        }
        int i = 1 - h % 3;
        int j = 1 - w % 3;
        b[i][j] = x;
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++) cout << b[i % 3][j % 3];
        cout << endl;
    }
}
0