結果

問題 No.3723 Climb or Detour
コンテスト
ユーザー tnakao0123
提出日時 2026-09-20 15:17:23
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 6 ms / 2,000 ms
+ 166µs
コード長 1,175 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 235 ms
コンパイル使用メモリ 55,156 KB
実行使用メモリ 9,924 KB
最終ジャッジ日時 2026-09-20 15:17:35
合計ジャッジ時間 4,853 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 58
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3723.cc:  No.3723 Climb or Detour - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

/* global variables */

char ss[MAX_N][MAX_N + 4];

/* subroutines */

/* main */

int main() {
  int n, k, sy, sx, ty, tx;
  scanf("%d%d%d%d%d%d", &n, &k, &sy, &sx, &ty, &tx);
  sy--, sx--, ty--, tx--;

  int d = abs(ty - sy) + abs(tx - sx);
  if (k < d || k > d * 2 || ((k - d) & 1)) { puts("-1"); return 0; }

  for (int i = 0; i < n; i++) fill(ss[i], ss[i] + n, '.');
  
  int c = (k - d) / 2;
  for (int i = 1; i <= c; i++) {
    int dd = i * 2 - 1;
    for (int y = sy, x = sx + dd; x > sx; y--, x--)
      if (y >= 0 && y < n && x >= 0 && x < n) ss[y][x] = '#';
    for (int y = sy - dd, x = sx; y < sy; y++, x--)
      if (y >= 0 && y < n && x >= 0 && x < n) ss[y][x] = '#';
    for (int y = sy, x = sx - dd; x < sx; y++, x++)
      if (y >= 0 && y < n && x >= 0 && x < n) ss[y][x] = '#';
    for (int y = sy + dd, x = sx; y > sy; y--, x++)
      if (y >= 0 && y < n && x >= 0 && x < n) ss[y][x] = '#';
  }

  for (int i = 0; i < n; i++) puts(ss[i]);
  
  return 0;
}

0