結果
問題 |
No.401 数字の渦巻き
|
ユーザー |
![]() |
提出日時 | 2018-07-27 21:47:04 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 671 bytes |
コンパイル時間 | 446 ms |
コンパイル使用メモリ | 62,300 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-04 23:34:25 |
合計ジャッジ時間 | 1,550 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#include <iostream> #include <iomanip> using namespace std; int main(){ int n; cin >> n; int map[n][n]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ map[i][j]=0; } } int p[2]={0,0}; int cnt=1; map[0][0]=cnt; cnt++; int a=1,b=1,c=0; while(cnt!=n*n+1){ p[a]+=b; if(map[p[0]][p[1]]!=0 || p[0]>=n || p[0]<0 || p[1]>=n || p[1]<0){ p[a]-=b; a=(a+1)%2; c++; if(c==2){ c=0; b*=-1; } }else{ map[p[0]][p[1]]=cnt; cnt++; } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++) cout << " " << setw(3) << setfill('0') << map[i][j]; cout << endl; } return 0; }