結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2022-07-23 05:47:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 859 bytes |
| コンパイル時間 | 2,526 ms |
| コンパイル使用メモリ | 196,296 KB |
| 最終ジャッジ日時 | 2025-01-30 13:13:45 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
cin>>n;
vector<vector<int>> A(n,vector<int> (n));
int ni=0,nj=0,di=0;
rep(i,n*n){
A[ni][nj]=i+1;
if(di==0){
if(nj+1<n && A[ni][nj+1]==0) nj++;
else di=1,ni++;
continue;
}
else if(di==1){
if(ni+1<n && A[ni+1][nj]==0) ni++;
else di=2,nj--;
continue;
}
else if(di==2){
if(nj>0 && A[ni][nj-1]==0) nj--;
else di=3,ni--;
continue;
}
else if(di==3){
if(ni>0 && A[ni-1][nj]==0) ni--;
else di=0,nj++;
}
}
rep(i,n){
rep(j,n){
if(j) printf(" ");
printf("%03d",A[i][j]);
}
printf("\n");
}
return 0;
}
umezo