結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-31 15:02:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 689 bytes |
| コンパイル時間 | 3,993 ms |
| コンパイル使用メモリ | 249,928 KB |
| 最終ジャッジ日時 | 2025-02-20 17:34:17 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
int n, now = 0, x = 0, y = 0;
string grid[33][33];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
cin >> n;
for (int i = 1; i <= n * n; i++) {
char s[20];
sprintf(s, "%03d", i);
grid[y][x] = s;
int nx = x + dx[now];
int ny = y + dy[now];
if (0 > nx || nx >= n || 0 > ny || ny >= n || grid[ny][nx] != "") {
now = (now + 1) % 4;
}
x += dx[now];
y += dy[now];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) cout << grid[i][j] << " \n"[j == n - 1];
}
return 0;
}