結果

問題 No.401 数字の渦巻き
ユーザー chacoder1chacoder1
提出日時 2021-05-01 14:52:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 929 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 199,172 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 04:48:43
合計ジャッジ時間 3,142 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long

int d[35][35];

signed main(void) {
  int n;
  cin>>n;
  int i=1;
  int j=1;
  int flag=0;
  //はじを埋めておく!
  for(int l=0;l<=n+1;l++){
    d[l][0]=1;
    d[0][l]=1;
    d[n+1][l]=1;
    d[l][n+1]=1;
  } 
  int k=1;
  while(k<=n*n){
     if(d[i][j]==0){
      d[i][j]=k;
      k++;
      continue;
    }
    if(flag==0){
      if(d[i][j+1]==0) j++;
      else flag++;
      continue;
    }
    if(flag==1){
      if(d[i+1][j]==0) i++;
      else flag++;
      continue;
    }
    if(flag==2){
      if(d[i][j-1]==0) j--;
      else flag++;
      continue;
    }
    if(flag==3){
      if(d[i-1][j]==0) i--;
      else flag=0;
      continue;
    }
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(j !=1) cout<<" ";
      cout<<setfill('0')<<right<<setw(3)<<d[i][j];
    }
    cout<<endl;
  }
 
  return 0;
}
0