結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
wing3196
|
| 提出日時 | 2016-07-22 22:27:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 718 bytes |
| コンパイル時間 | 1,732 ms |
| コンパイル使用メモリ | 157,824 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 08:59:03 |
| 合計ジャッジ時間 | 2,261 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = LLONG_MAX/2;
const int dx[] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int N;
int fld[30][30];
bool isUsed[30][30];
void DFS(int x, int y, int d, int cnt)
{
fld[y][x] = cnt;
for (int i = 0; i < 4; i++)
{
int nx = x + dx[(d + i) % 4], ny = y + dy[(d + i) % 4];
if (nx < 0 || N <= nx || ny < 0 || N <= ny || isUsed[ny][nx]) continue;
isUsed[ny][nx] = true;
DFS(nx, ny, (d + i) % 4, ++cnt);
break;
}
}
signed main()
{
isUsed[0][0] = true;
cin >> N;
DFS(0, 0, 0, 1);
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (j) printf(" ");
printf("%03lld", fld[i][j]);
}
puts("");
}
return 0;
}
wing3196