結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-22 22:49:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 720 bytes |
| コンパイル時間 | 754 ms |
| コンパイル使用メモリ | 75,116 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-06 09:09:03 |
| 合計ジャッジ時間 | 1,725 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:34:20: warning: 'y' may be used uninitialized [-Wmaybe-uninitialized]
34 | ny = (y + dy[dir]);
| ~~~^~~~~~~~~~~~~~~
main.cpp:21:16: note: 'y' was declared here
21 | int x, y;
| ^
main.cpp:33:20: warning: 'x' may be used uninitialized [-Wmaybe-uninitialized]
33 | nx = (x + dx[dir]);
| ~~~^~~~~~~~~~~~~~~
main.cpp:21:13: note: 'x' was declared here
21 | int x, y;
| ^
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
int main() {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n, -1));
int nx = 0;
int ny = 0;
int dir = 0;
int x, y;
int z = 1;
while (z <= n*n) {
while (0 <= nx && nx < n && 0 <= ny && ny < n && a[ny][nx] == -1) {
x = nx;
y = ny;
a[y][x] = z;
nx = (x + dx[dir]);
ny = (y + dy[dir]);
z++;
}
dir = (dir + 1) % 4;
nx = (x + dx[dir]);
ny = (y + dy[dir]);
}
for (auto aa : a) {
for (auto aaa : aa) {
printf("%03d ", aaa);
}
printf("\n");
}
return 0;
}