結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2017-07-08 12:03:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,073 bytes |
コンパイル時間 | 721 ms |
コンパイル使用メモリ | 83,064 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-06 19:39:40 |
合計ジャッジ時間 | 1,773 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#include <iostream>#include <cstdio>#include <cmath>#include <cstdio>#include <cstring>#include <string>#include <vector>#include <set>#include <map>#include <stack>#include <queue>#include <deque>#include <algorithm>#define CK(N,A,B) (A<=N&&N<B)#define REP(i,a,b) for(int i=a;i<b;i++)#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)#define F first#define S second#define ll long longconst int INF = 1e9;const long long LLINF = 1e15;using namespace std;int dx[] = {1,0,-1,0};int dy[] = {0,1,0,-1};int N, num=1, cnt=0;int d[35][35];int main(){cin>>N;int k = 0;int range=N-1;int posy = 0, posx = 0;d[posy][posx] = 1;while(1){REP(i,0,range){num++;posy += dy[k];posx += dx[k];d[posy][posx] = num;}k = (k+1)%4;if(range != N-1) cnt++;if(num == N*N) break;if(range != N-1 && cnt%2==0){range--;}else if(range == N-1 && num == 3*N-2){range--;}}REP(i,0,N){REP(j,0,N){printf("%03d ", d[i][j]);}cout<<endl;}return 0;}