結果

問題 No.401 数字の渦巻き
ユーザー fura
提出日時 2020-04-01 02:04:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 423 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 193,316 KB
最終ジャッジ日時 2025-01-09 11:23:45
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         int n; scanf("%d",&n);
      |                ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

int main(){
	int n; scanf("%d",&n);

	int a[30][30]={},y=0,x=0,k=0;
	rep(i,n*n){
		a[y][x]=i+1;
		int y2=y+dy[k],x2=x+dx[k];
		if(y2<0 || n<=y2 || x2<0 || n<=x2 || a[y2][x2]!=0) k=(k+1)%4;
		y+=dy[k];
		x+=dx[k];
	}
	rep(i,n) rep(j,n) printf("%03d%c",a[i][j],j<n-1?' ':'\n');

	return 0;
}
0