結果
| 問題 | No.401 数字の渦巻き |
| コンテスト | |
| ユーザー |
ldsyb
|
| 提出日時 | 2018-07-27 21:50:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 702 bytes |
| 記録 | |
| コンパイル時間 | 1,673 ms |
| コンパイル使用メモリ | 171,792 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-04 23:42:35 |
| 合計ジャッジ時間 | 2,465 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n, 0));
pair<int, int> now(0, 0);
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}, p = 0;
auto inside = [](int a, int b, int alim, int blim) {
return 0 <= a && a < alim && 0 <= b && b < blim;
};
for (int num = 1; num <= n * n; num++)
{
a[now.first][now.second] = num;
if (!inside(now.first + dx[p], now.second + dy[p], n, n) || a[now.first + dx[p]][now.second + dy[p]])
{
p++;
p %= 4;
}
now.first += dx[p];
now.second += dy[p];
}
for (auto &i : a)
{
for (auto &j : i)
{
cout << setw(3) << setfill('0') << j << ' ';
}
cout << endl;
}
return 0;
}
ldsyb