結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
femto
|
| 提出日時 | 2016-07-22 22:30:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 689 bytes |
| コンパイル時間 | 725 ms |
| コンパイル使用メモリ | 67,412 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 09:02:39 |
| 合計ジャッジ時間 | 1,778 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
int b[30][30];
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
int nx = 0, ny = 0, dir = 0;
for(int i = 1; i <= N * N; i++) {
b[ny][nx] = i;
int nnx = nx + dx[dir], nny = ny + dy[dir];
if(nnx < 0 || N <= nnx || nny < 0 || N <= nny || b[nny][nnx] != 0) {
dir = (dir + 1) % 4;
}
nx += dx[dir];
ny += dy[dir];
}
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
cout << setw(3) << setfill('0') << b[i][j] << " ";
}
cout << endl;
}
}
femto