結果

問題 No.401 数字の渦巻き
ユーザー Yug_min_nullYug_min_null
提出日時 2021-11-15 21:37:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,033 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 193,728 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 16:39:30
合計ジャッジ時間 3,692 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _GLIBCXX_DEBUG
#define ll long long
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main(){
  int N; cin >> N;
  vector<vector<int>> A(N+2, vector<int>(N+2, -1));
  A[1][1] = 1;
  int y = 1, x = 1;
  char D = 'R';
  for(int i = 2; i <= N*N; i++){
    switch(D){
      case 'R':
        x++;
        A[y][x] = i;
        if(x == N or A[y][x+1] != -1){
          D = 'D';
        }
        break;
      case 'D':
        y++;
        A[y][x] = i;
        if(y == N or A[y+1][x] != -1){
          D = 'L';
        }
        break;
      case 'L':
        x--;
        A[y][x] = i;
        if(x == 1 or A[y][x-1] != -1){
          D = 'U';
        }
        break;
      case 'U':
        y--;
        A[y][x] = i;
        if(y == 1 or A[y-1][x] != -1){
          D = 'R';
        }
        break;
    }
  }
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= N; j++){
      if(j == N){
        printf("%03d\n", A[i][j]);
      }else{
        printf("%03d ", A[i][j]);
      }
    }
  }
}
0