結果

問題 No.401 数字の渦巻き
ユーザー kimiyukikimiyuki
提出日時 2016-07-22 22:46:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,203 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 60,252 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 02:25:28
合計ジャッジ時間 1,179 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <typename T, typename X> auto vectors(T a, X x) { return vector<T>(x, a); }
template <typename T, typename X, typename Y, typename... Zs> auto vectors(T a, X x, Y y, Zs... zs) { auto cont = vectors(a, y, zs...); return vector<decltype(cont)>(x, cont); }
const int dy[] = { 0, 1, 0, -1 };
const int dx[] = { 1, 0, -1, 0 };
int main() {
    int n; scanf("%d", &n);
    vector<vector<int> > f = vectors(0, n+2, n+2);
    repeat_from (i,1,n+1) {
        f[i][  0] = -1;
        f[i][n+1] = -1;
        f[  0][i] = -1;
        f[n+1][i] = -1;
    }
    function<void (int, int, int, int)> dfs = [&](int y, int x, int i, int j) {
        f[y][x] = i;
        if (i == n*n) return;
        int ny = y + dy[j];
        int nx = x + dx[j];
        if (f[ny][nx]) {
            dfs(y, x, i, (j+1)%4);
        } else {
            dfs(ny, nx, i+1, j);
        }
    };
    dfs(1, 1, 1, 0);
    repeat_from (y,1,n+1) {
        repeat_from (x,1,n+1) {
            printf("%03d ", f[y][x]);
        }
        printf("\n");
    }
    return 0;
}
0