結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
a01sa01to
|
| 提出日時 | 2024-08-15 00:52:28 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 745 bytes |
| コンパイル時間 | 3,597 ms |
| コンパイル使用メモリ | 249,428 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-08-15 00:52:34 |
| 合計ジャッジ時間 | 4,482 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "settings/debug.cpp"
#else
#define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
int main() {
int n;
cin >> n;
vector a(n, vector<int>(n));
vector<int> dx = { 0, 1, 0, -1 };
vector<int> dy = { 1, 0, -1, 0 };
int x = 0, y = 0, d = 0;
rep(_, n * n) {
a[x][y] = _ + 1;
int nx = x + dx[d];
int ny = y + dy[d];
if (nx < 0 || nx >= n || ny < 0 || ny >= n || a[nx][ny]) {
d = (d + 1) % 4;
nx = x + dx[d];
ny = y + dy[d];
}
x = nx, y = ny;
}
rep(i, n) rep(j, n) {
printf("%03d%c", a[i][j], j == n - 1 ? '\n' : ' ');
}
return 0;
}
a01sa01to