結果
| 問題 | No.401 数字の渦巻き |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-09 06:18:52 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1 ms / 2,000 ms |
| + 981µs | |
| コード長 | 1,071 bytes |
| 記録 | |
| コンパイル時間 | 2,462 ms |
| コンパイル使用メモリ | 350,104 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-11-09 06:18:58 |
| 合計ジャッジ時間 | 5,070 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
using i128 = __int128;
constexpr int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
void solve() {
int N; std::cin >> N;
auto f = [&](int x) -> std::string {
std::string s = std::to_string(x);
while(s.size() < 3) s = "0" + s;
return s;
};
std::vector ans(N, std::vector<std::string> (N, ""));
auto ok = [&](int x, int y, int d) -> bool {
int nx = x + dx[d], ny = y + dy[d];
if(nx < 0 || nx >= N || ny < 0 || ny >= N) return false;
if(ans[nx][ny] != "") return false;
return true;
};
int x = 0, y = 0, d = 0;
for(int i = 1; i <= N * N; i ++) {
ans[x][y] = f(i);
if(!ok(x, y, d)) d = (d + 1) % 4;
x += dx[d];
y += dy[d];
}
for(int i = 0; i < N; i ++) {
for(int j = 0; j < N; j ++) std::cout << ans[i][j] << " ";
std::cout << "\n";
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T = 1;
//std::cin >> T;
while (T--) {
solve();
}
return 0;
}