結果
問題 |
No.401 数字の渦巻き
|
ユーザー |
![]() |
提出日時 | 2022-05-20 22:20:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,466 bytes |
コンパイル時間 | 903 ms |
コンパイル使用メモリ | 97,996 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-20 08:32:53 |
合計ジャッジ時間 | 2,060 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
// yukicodr // No.401 数字の渦巻き // //#include "stdafx.h" #include <iostream> #include <vector> #include <list>//list #include <set> //tree #include <map> //連想配列 #include <unordered_set> //hash #include <unordered_map> //hash #include <algorithm> #include <iomanip> using namespace std; #define RIGHT (1) #define LEFT (2) #define UP (3) #define DOWN (4) vector <vector <int>> mass; int N; void solve(int i, int x, int y, int dir) { if (i > N * N) return; mass[y][x] = i; switch (dir) { case RIGHT: if (x + 1 < N && mass[y][x+1] == 0) { x++; } else { y++; dir = DOWN; } break; case LEFT: if (x - 1 >= 0 && mass[y][x - 1] == 0) { x--; } else { y--; dir = UP; } break; case UP: if (y - 1 >= 0 && mass[y-1][x] == 0) { y--; } else { x++; dir = RIGHT; } break; case DOWN: if (y + 1 < N && mass[y+1][x] == 0) { y++; } else { x--; dir = LEFT; } break; } solve(i+1,x,y,dir); } int main() { cin >> N; mass.resize(N); for (int i = 0; i < N; i++) { mass[i].resize(N); } for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { mass[y][x] = 0; } } solve(1, 0, 0, RIGHT); for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { cout << setfill('0') << setw(3) << right << mass[y][x]<<" "; } cout << endl; } //getchar(); return 0; }