結果
問題 | No.217 魔方陣を作ろう |
ユーザー | kakira9618 |
提出日時 | 2015-05-26 23:26:46 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,406 bytes |
コンパイル時間 | 723 ms |
コンパイル使用メモリ | 94,728 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-06 10:28:19 |
合計ジャッジ時間 | 1,418 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | WA | - |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | WA | - |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | WA | - |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | WA | - |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | WA | - |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | WA | - |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | WA | - |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | WA | - |
ソースコード
#include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <string> #include <vector> #include <complex> #include <cstdlib> #include <cstring> #include <numeric> #include <sstream> #include <iostream> #include <algorithm> #include <functional> #define mp make_pair #define pb push_back #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef pair<int,int> pii; const int INF=1<<29; const double EPS=1e-9; int main(int argc, char const *argv[]) { int N; cin >> N; std::vector<vector<int> > m(N, vector<int>(N, 0)); std::vector<vector<int> > ok(N, vector<int>(N, 0)); if (N % 2 == 1) { int px = N / 2; int py = 0; int count = 0; while(count != N * N) { if (m[py][px] != 0) { py = (py + 1) % N; px = (px + N - 1) % N; py = (py + 1) % N; } else { m[py][px] = count + 1; px = (px + 1) % N; py = (py + N - 1) % N; count++; } } } else if (N % 4 == 0) { for (int i = 0; i < N / 4; ++i) { for (int j = 0; j < N / 4; ++j) { ok[i * 4][j * 4] = 1; ok[i * 4 + 1][j * 4 + 1] = 1; ok[i * 4 + 2][j * 4 + 2] = 1; ok[i * 4 + 3][j * 4 + 3] = 1; ok[i * 4 + 3][j * 4] = 1; ok[i * 4 + 2][j * 4 + 1] = 1; ok[i * 4 + 1][j * 4 + 2] = 1; ok[i * 4][j * 4 + 3] = 1; } } int count = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (ok[i][j]) { m[i][j] = ++count; } } } for (int i = N - 1; i >= 0; i--) { for (int j = N - 1; j >= 0; j--) { if (!ok[i][j]) { m[i][j] = ++count; } } } } else { int n = N / 2; std::vector<vector<char> > lux(n, vector<char>(n, 0)); std::vector<vector<char> > lux_m(n, vector<char>(n, 0)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i <= n / 2) {lux[i][j] = 'l';} else if (i == n / 2 + 1) {lux[i][j] = 'u';} else {lux[i][j] = 'x';} } } int px = N / 2; int py = 0; int count = 0; while(count != n * n) { if (lux_m[py][px] != 0) { py = (py + 1) % n; px = (px + n - 1) % n; py = (py + 1) % n; } else { lux_m[py][px] = count + 1; px = (px + 1) % n; py = (py + n - 1) % n; count++; } } char temp = lux[n / 2][n / 2]; lux[n / 2][n / 2] = lux[n / 2 + 1][n / 2]; lux[n / 2 + 1][n / 2] = temp; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { int px = 2 * j; int py = 2 * i; if (lux[i][j] == 'l') { m[py][px] = lux_m[i][j] + 4; m[py + 1][px] = lux_m[i][j] + 2; m[py][px + 1] = lux_m[i][j] + 1; m[py + 1][px + 1] = lux_m[i][j] + 3; } else if (lux[i][j] == 'u') { m[py][px] = lux_m[i][j] + 1; m[py + 1][px] = lux_m[i][j] + 2; m[py][px + 1] = lux_m[i][j] + 4; m[py + 1][px + 1] = lux_m[i][j] + 3; } else { m[py][px] = lux_m[i][j] + 1; m[py + 1][px] = lux_m[i][j] + 3; m[py][px + 1] = lux_m[i][j] + 4; m[py + 1][px + 1] = lux_m[i][j] + 2; } } } } for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { cout << m[i][j] << " "; } cout << endl; } return 0; }