結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-01 20:34:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 705 bytes |
| コンパイル時間 | 1,654 ms |
| コンパイル使用メモリ | 170,968 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-08 01:32:28 |
| 合計ジャッジ時間 | 2,540 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int n;
cin >> n;
vector<vector<int>> ans(n, vector<int>(n));
int num = 1;
int x = 0, y = 0, d = 0;
for(int i = 0; i < n * n; i++) {
ans[x][y] = num;
num++;
int xx = x + dx[d % 4];
int yy = y + dy[d % 4];
if(xx >= 0 && yy >= 0 && xx < n && yy < n && !ans[xx][yy]) {
x = xx;
y = yy;
} else {
d++;
x = x + dx[d % 4];
y = y + dy[d % 4];
}
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(j > 0) cout << " ";
cout << setw(3) << setfill('0') << ans[i][j];
}
cout << '\n';
}
return 0;
}