結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2018-07-21 15:54:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 628 bytes |
コンパイル時間 | 1,887 ms |
コンパイル使用メモリ | 166,964 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-26 04:53:35 |
合計ジャッジ時間 | 3,274 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#include<bits/stdc++.h>using namespace std;using Int = long long;//INSERT ABOVE HEREInt ans[40][40];signed main(){Int n;cin>>n;memset(ans,0,sizeof(ans));auto in=[&](Int y,Int x){return 0<=y&&y<n&&0<=x&&x<n;};Int dy[]={0,1,0,-1};Int dx[]={1,0,-1,0};Int y=0,x=0,d=0,s=0;while(!ans[y][x]){ans[y][x]=++s;Int ny=y+dy[d],nx=x+dx[d];if(!in(ny,nx)||ans[ny][nx]){d++;d%=4;ny=y+dy[d];nx=x+dx[d];}y=ny;x=nx;}for(Int i=0;i<n;i++){for(Int j=0;j<n;j++){if(j) cout<<" ";cout<<setfill('0')<<setw(3)<<ans[i][j];}cout<<endl;}return 0;}