結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
hotpepsi
|
| 提出日時 | 2016-07-25 00:43:14 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 610 bytes |
| コンパイル時間 | 496 ms |
| コンパイル使用メモリ | 56,372 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 16:04:27 |
| 合計ジャッジ時間 | 1,446 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <iostream>
#include <sstream>
#include <cstdio>
using namespace std;
int main(int argc, char *argv[])
{
int N;
int n[32][32] = {};
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int d = 0, x = -1, y = 0;
cin >> N;
for (int i = 1; i <= N * N; ++i) {
int nx = x + dx[d], ny = y + dy[d];
if (nx < 0 || nx >= N || ny < 0 || ny >= N || n[ny][nx]) {
d = (d + 1) % 4;
nx = x + dx[d], ny = y + dy[d];
}
x = nx, y = ny;
n[y][x] = i;
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
printf("%s%03d", j ? " " : "", n[i][j]);
}
printf("\n");
}
return 0;
}
hotpepsi