結果
問題 | No.401 数字の渦巻き |
ユーザー |
|
提出日時 | 2016-07-22 22:25:57 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 614 bytes |
コンパイル時間 | 1,262 ms |
コンパイル使用メモリ | 158,600 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 08:56:07 |
合計ジャッジ時間 | 2,230 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; static int a[30][30]; const int dy[] = { 0, 1, 0, -1 }; const int dx[] = { 1, 0, -1, 0 }; int y = 0; int x = 0; int k = 0; for (int i = 1; i <= n * n; i++) { a[y][x] = i; if (i == n * n) break; while (true) { int ny = y + dy[k]; int nx = x + dx[k]; if (ny < 0 || nx < 0 || ny >= n || nx >= n || a[ny][nx] != 0) { k = (k + 1) % 4; continue; } y = ny; x = nx; break; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { printf("%03d ", a[i][j]); } cout << endl; } }