結果

問題 No.223 1マス指定の魔方陣
ユーザー pekempeypekempey
提出日時 2015-06-05 23:51:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,869 bytes
コンパイル時間 1,132 ms
コンパイル使用メモリ 145,144 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 19:28:46
合計ジャッジ時間 3,380 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,384 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:89:17: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     int dx = (x - X + N) % N;
               ~~^~~
main.cpp:88:17: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     int dy = (y - Y + N) % N;
               ~~^~~

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fr(i, a, b) for (int i = (a); i < (b); i++)
#define all(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

int N, X, Y, Z;

int a[16][16];
int b[16][16];

void build() {
    if (N == 4) {
        a[0][0] = 0;
        a[0][1] = 1;
        a[0][2] = 3;
        a[0][3] = 2;
    } else if (N == 8) {
        a[0][0] = 7;
        a[0][1] = 1;
        a[0][2] = 5;
        a[0][3] = 3;
        a[0][4] = 0;
        a[0][5] = 6;
        a[0][6] = 2;
        a[0][7] = 4;
    } else {
        a[0][0] = 7;
        a[0][1] = 9;

        a[0][2] = 5;
        a[0][3] = 11;

        a[0][4] = 0;
        a[0][5] = 14;

        a[0][6] = 2;
        a[0][7] = 12;

        a[0][8] = 15;
        a[0][9] = 1;

        a[0][10] = 13;
        a[0][11] = 3;

        a[0][12] = 8;
        a[0][13] = 6;

        a[0][14] = 10;
        a[0][15] = 4;

    }

    for (int i = 1; i < N; i++) {
        rep (j, N) {
            a[i][(j + i * 2) % N] = a[0][j];
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            b[j][i] = a[i][j];
        }
    }

    rep (i, N) {
        rep (j, N) {
            a[i][j] = a[i][j] * N + b[i][j] + 1;
        }
    }
}


void solve() {
    int y, x;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (Z == a[i][j]) {
                y = i;
                x = j;
            }
        }
    }

    int dy = (y - Y + N) % N;
    int dx = (x - X + N) % N;

    rep (i, N) {
        rep (j, N) {
            if (j > 0) cout << " ";
            cout << a[(i + dy) % N][(j + dx) % N];
        }
        cout << endl;
    }
    cout << endl;
}

int main() {
    cin >> N >> X >> Y >> Z;
    X--; Y--;

    build();
    solve();
}
0