結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
newlife171128
|
| 提出日時 | 2018-01-16 23:14:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,241 bytes |
| コンパイル時間 | 744 ms |
| コンパイル使用メモリ | 88,148 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-24 05:55:59 |
| 合計ジャッジ時間 | 1,671 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
typedef long long ll;
using namespace std;
int uzu[31][31];
bool trac[31][31];
int main() {
int n=0;
cin>>n;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
trac[i][j] = true;
}
}
queue<int> q;
q.push(1);
int x=0,y=0;
while(!q.empty()){
int tmp = q.front();q.pop();
if(tmp >n*n){
continue;
}
trac[y][x] =false;
uzu[y][x] = tmp;
if(trac[y][x+1] == true && x+1<n){
if(trac[y-1][x] == true && y-1>=0){
q.push(tmp+1);
y--;;
continue;
}
q.push(tmp+1);
x++;
continue;
}
if(trac[y+1][x] == true && y+1<n){
q.push(tmp+1);
y++;
continue;
}
if(trac[y][x-1] == true && x-1>=0){
q.push(tmp+1);
x--;;
continue;
}
if(trac[y-1][x] == true && y-1>=0){
q.push(tmp+1);
y--;;
continue;
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
cout<<setfill('0')<<right<<setw(3)<<uzu[i][j]<<" ";
}
cout<<endl;
}
/* cout<<setfill('0')<<right<<setw(3)<<10<<endl;*/
return 0;
}
newlife171128