結果
| 問題 |
No.223 1マス指定の魔方陣
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-06-05 23:42:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,316 bytes |
| コンパイル時間 | 1,223 ms |
| コンパイル使用メモリ | 159,592 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-06 14:24:12 |
| 合計ジャッジ時間 | 2,804 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 16 WA * 30 |
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:107:17: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
107 | int dx = (x - X + N) % N;
| ~~^~~
main.cpp:106:17: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized]
106 | int dy = (y - Y + N) % N;
| ~~^~~
ソースコード
#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 a4[4][4] = {
{ 1, 8, 13, 12 },
{ 14, 11, 2, 7 },
{ 4, 5, 16, 9 },
{ 15, 10, 3, 6 },
};
int a8[8][8] = {
{ 64, 11, 41, 30, 8, 51, 17, 38 },
{ 18, 37, 63, 12, 42, 29, 7, 52 },
{ 6, 56, 19, 33, 62, 16, 43, 25 },
{ 44, 26, 5, 55, 20, 34, 61, 15 },
{ 57, 14, 48, 27, 1, 54, 24, 35 },
{ 23, 36, 58, 13, 47, 28, 2, 53 },
{ 3, 49, 22, 40, 59, 9, 46, 32 },
{ 45, 31, 4, 50, 21, 39, 60, 10 },
};
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] = 1;
a[0][4] = 0;
a[0][5] = 6;
a[0][6] = 2;
a[0][7] = 4;
} else {
a[0][0] = 7;
a[0][1] = 1;
a[0][2] = 5;
a[0][3] = 1;
a[0][4] = 0;
a[0][5] = 6;
a[0][6] = 2;
a[0][7] = 4;
a[0][8] = 15;
a[0][9] = 9;
a[0][10] = 13;
a[0][11] = 9;
a[0][12] = 8;
a[0][13] = 14;
a[0][14] = 10;
a[0][15] = 12;
}
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();
}