結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
kpinkcat
|
| 提出日時 | 2023-08-14 03:53:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 830 bytes |
| コンパイル時間 | 1,098 ms |
| コンパイル使用メモリ | 107,104 KB |
| 最終ジャッジ日時 | 2025-02-16 08:02:21 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>
#include<set>
#include<bitset>
#include<math.h>
#include<map>
#include<queue>
#include<iomanip>
using namespace std;
#ifdef _WIN32
#include <Windows.h>
#endif
int main()
{
int n, x = 0, y = 0, num = 1, dir = 0;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
cin >> n;
vector<vector<int>> v(n, vector<int>(n, 0));
for (int i = 0; i < n*n; i++){
v[y][x] = i + 1;
int tx = x + dx[dir%4], ty = y + dy[dir%4];
if ((tx >= n) || (ty >= n) || (tx < 0) || (ty < 0) || (v[ty][tx] != 0)) dir++;
x += dx[dir%4];
y += dy[dir%4];
}
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
printf("%03d", v[i][j]);
cout << ((j != n-1) ? " " : "\n");
}
}
}
kpinkcat