結果

問題 No.48 ロボットの操縦
ユーザー intercept6intercept6
提出日時 2020-09-10 15:29:21
言語 TypeScript
(5.4.3)
結果
AC  
実行時間 76 ms / 5,000 ms
コード長 848 bytes
コンパイル時間 10,368 ms
コンパイル使用メモリ 258,252 KB
実行使用メモリ 44,392 KB
最終ジャッジ日時 2023-08-24 22:49:20
合計ジャッジ時間 12,624 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
42,464 KB
testcase_01 AC 75 ms
42,352 KB
testcase_02 AC 74 ms
42,200 KB
testcase_03 AC 74 ms
42,660 KB
testcase_04 AC 74 ms
42,208 KB
testcase_05 AC 76 ms
44,392 KB
testcase_06 AC 75 ms
42,280 KB
testcase_07 AC 75 ms
42,196 KB
testcase_08 AC 76 ms
42,212 KB
testcase_09 AC 75 ms
42,348 KB
testcase_10 AC 75 ms
42,228 KB
testcase_11 AC 75 ms
42,344 KB
testcase_12 AC 76 ms
42,296 KB
testcase_13 AC 75 ms
42,344 KB
testcase_14 AC 76 ms
42,204 KB
testcase_15 AC 76 ms
42,472 KB
testcase_16 AC 75 ms
42,280 KB
testcase_17 AC 75 ms
42,344 KB
testcase_18 AC 75 ms
42,224 KB
testcase_19 AC 76 ms
42,228 KB
testcase_20 AC 75 ms
42,396 KB
testcase_21 AC 76 ms
42,280 KB
testcase_22 AC 75 ms
42,288 KB
testcase_23 AC 76 ms
42,288 KB
testcase_24 AC 75 ms
42,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import { readFileSync } from 'fs';

function Main(input: string) {
  const data = input.split('\n');

  const positionX = parseInt(data[0]);
  const positionY = parseInt(data[1]);
  const distance = parseInt(data[2]);

  let step = 0;

  // Y軸方向へ正方向の移動(↑)を行う場合
  if (positionY > 0) {
    step += Math.ceil(positionY / distance);
  }

  // X軸へ移動(←→)を行う場合
  // 絶対値を取って計算する
  if (positionX !== 0) {
    step++; //  回転
    step += Math.ceil(Math.abs(positionX) / distance);
  }

  // Y軸方向へ負方向の移動(↓)を行う場合
  if (positionY < 0) {
    if (positionX === 0) {
      step += 2;
    } else {
      step++;
    }

    step += Math.ceil((-1 * positionY) / distance);
  }

  console.log(step);
}

Main(readFileSync('/dev/stdin', 'utf8'));
0