結果

問題 No.401 数字の渦巻き
ユーザー aoringo0606aoringo0606
提出日時 2023-01-19 20:25:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,759 bytes
コンパイル時間 1,750 ms
コンパイル使用メモリ 170,096 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-04 11:33:42
合計ジャッジ時間 3,722 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"

#pragma warning(disable : 4996)

typedef long long ll;
#define all(x) (x).begin(), (x).end() // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER // デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) \
  cout
#define debug() if (false)
#define check(x) \
  if (false)     \
  cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false)    \
  cout << "☆" << x << endl
#endif

using namespace std;
// #define int long long;

double dist(double x1, double y1, double x2, double y2)
{
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
ll idist(ll x1, ll y1, ll x2, ll y2)
{
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

signed main()
{
  ll n;
  cin >> n;
  ll x = 0,y = 0;
  ll dir = 0;
  vector<vector<ll>> vv(n,vector<ll>(n,-1));
  rep(i,n*n){
    vv[x][y] = i+1;
    if(dir == 0){
      x++;
      if(x == n-1 || vv[x+1][y] != -1){
        dir = 1;
      }
    }
    else if(dir == 1){
      y++;
      if(y == n-1 || vv[x][y+1] != -1){
        dir = 2;
      }
    }
    else if(dir == 2){
      x--;
      if(x == 0 || vv[x-1][y] != -1){
        dir = 3;
      }
    }
    else if(dir == 3){
      y--;
      if(y == 0  || vv[x][y-1] != -1){
        dir = 0;
      }
    }

  }
  rep(i,n){
    rep(j,n){
      if(vv[j][i] < 10) cout << "00" << vv[j][i] << " ";
      else if(vv[j][i] < 100) cout << 0 << vv[j][i] << " ";
      else cout << vv[j][i] << " ";
    }
    cout << endl;
  }
}
0