結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
kyo1
|
| 提出日時 | 2020-10-02 14:29:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 2,000 ms |
| コード長 | 733 bytes |
| コンパイル時間 | 2,061 ms |
| コンパイル使用メモリ | 199,280 KB |
| 最終ジャッジ日時 | 2025-01-14 23:54:29 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const std::vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<vector<int>> res(N, vector<int>(N, 0));
int cur = 0;
int y = 0, x = 0;
for (int i = 0; i < N * N; i++) {
res[y][x] = i + 1;
int ny = y + dy[cur], nx = x + dx[cur];
if (ny < 0 || ny >= N || nx < 0 || nx >= N || res[ny][nx] != 0) {
cur = (cur + 1) % 4;
ny = y + dy[cur], nx = x + dx[cur];
}
y = ny, x = nx;
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cout << setfill('0') << right << setw(3) << res[i][j] << (j == N - 1 ? '\n' : ' ');
}
}
return 0;
}
kyo1