結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
aaa
|
| 提出日時 | 2018-10-29 21:22:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 2,007 bytes |
| コンパイル時間 | 1,388 ms |
| コンパイル使用メモリ | 105,408 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-19 08:14:09 |
| 合計ジャッジ時間 | 2,039 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
using namespace std;
int main(){
int i, j;
int n;
vector<vector<bool>>flag(55, vector<bool>(55, false));
vector<vector<int>>matrix(55, vector<int>(55, 0));
int x = 0, y = 0, num = 1;
cin >> n;
if (n == 1) {
cout << "001" << endl;
return 0;
}
else if (n == 2) {
cout << "001" << " " << "002" << endl;
cout << "004" << " " << "003" << endl;
return 0;
}
while (true) {
bool flag2 = false;
for (i = 0; i < n; i++) {
if (flag[y][x] == true) {
break;
}
else {
matrix[y][x] = num;
flag[y][x] = true;
x++;
num++;
flag2 = true;
}
}
x--;
y++;
for (i = 0; i < n - 1; i++) {
if (flag[y][x] == true) {
break;
}
else {
matrix[y][x] = num;
flag[y][x] = true;
y++;
num++;
flag2 = true;
}
}
y--;
x--;
for (i = 0; i < n - 1; i++) {
if (flag[y][x] == true || x < 0) {
break;
}
else {
matrix[y][x] = num;
flag[y][x] = true;
x--;
num++;
flag2 = true;
}
}
x++;
y--;
for (i = 0; i < n - 1; i++) {
if (flag[y][x] == true) {
break;
}
else {
matrix[y][x] = num;
flag[y][x] = true;
y--;
num++;
flag2 = true;
}
}
x++;
y++;
if (flag2 == false) {
break;
}
/* for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
cout << setw(3) << setfill('0') << matrix[i][j];
if (j != n - 1) {
cout << " ";
}
}
cout << endl;
}
cout << endl;*/
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
cout << setw(3) << setfill('0') << matrix[i][j];
if (j != n - 1) {
cout << " ";
}
}
cout << endl;
}
getchar();
getchar();
return 0;
}
aaa