結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
moyashi_senpai
|
| 提出日時 | 2016-07-22 22:39:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,163 bytes |
| コンパイル時間 | 613 ms |
| コンパイル使用メモリ | 74,380 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 09:06:09 |
| 合計ジャッジ時間 | 1,578 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
24 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
using namespace std;
#define Getsign(n) ((n > 0) - (n < 0))
typedef vector<int> Ivec;
typedef pair<int, int> Pos;
const pair<int, int> dira[4] = { {0,1},{1,0},{0,-1},{-1,0} };
int main() {
int n;
int m[32][32] = {};
scanf("%d", &n);
for (int i = 0; n + 1 > i; i++) {
m[i][0] = -1;
m[0][i] = -1;
m[n + 1][i] = -1;
m[i][n + 1] = -1;
}
Pos pos = { 1 ,1};
int cou = 1;
int dir = 0;
while (1) {
if (m[pos.first][pos.second] != 0) {
pos.first -= dira[dir].first;
pos.second -= dira[dir].second;
dir = (dir + 1) % 4;
pos.first += dira[dir].first;
pos.second += dira[dir].second;
if (m[pos.first][pos.second]!= 0) {
break;
}
continue;
}
m[pos.first][pos.second] = cou;
pos.first += dira[dir].first;
pos.second += dira[dir].second;
cou++;
}
for (int i = 1; n + 1 > i; i++) {
for (int j = 1; n + 1 > j; j++) {
printf("%03d", m[i][j]);
if (j != n)printf(" ");
}
printf("\n");
}
return 0;
}
moyashi_senpai