結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-17 22:04:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,155 bytes |
| コンパイル時間 | 1,594 ms |
| コンパイル使用メモリ | 114,068 KB |
| 最終ジャッジ日時 | 2025-01-18 21:54:47 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <optional>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
int main() {
int32_t n;
cin >> n;
vector<vector<int32_t>> mat(n, vector<int32_t>(n));
int32_t x = 0, y = 0, c = 1;
for (auto d = n - 1; d > 0; d -= 2) {
for (auto i = 0; i < d; ++i) {
mat[x][y] = c;
++c;
++x;
}
for (auto i = 0; i < d; ++i) {
mat[x][y] = c;
++c;
++y;
}
for (auto i = 0; i < d; ++i) {
mat[x][y] = c;
++c;
--x;
}
for (auto i = 0; i < d; ++i) {
mat[x][y] = c;
++c;
--y;
}
++x;
++y;
}
if (n % 2 == 1)
mat[x][y] = c;
for (auto i = 0; i < n; ++i) {
for (auto j = 0; j < n; ++j) {
printf("%03d%c", mat[j][i], j == n - 1 ? '\n' : ' ');
}
}
return 0;
}