Submission #58184466


Source Code Expand

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

#define rep(i, x) for (int i = 0; i < (x); i++)

int main()
{
  string S;
  cin >> S;
  vector<int> position(26);
  for (int i = 0; i < 26; ++i)
  {
    position[S[i] - 'A'] = i;
  }

  // 最初の位置は 'A' の場所
  int currentPos = position[0]; // 'A'の位置
  int totalDistance = 0;        // 合計移動距離

  // 'B' から 'Z' まで順に移動していく
  for (char c = 'B'; c <= 'Z'; ++c)
  {
    int nextPos = position[c - 'A'];            // 次の文字の位置
    totalDistance += abs(nextPos - currentPos); // 移動距離を足す
    currentPos = nextPos;                       // 現在の位置を更新
  }

  // 結果を出力
  cout << totalDistance << endl;
  return 0;
}

Submission Info

Submission Time
Task B - 1D Keyboard
User ryoh1004
Language C++ 23 (gcc 12.2)
Score 200
Code Size 779 Byte
Status AC
Exec Time 1 ms
Memory 3648 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 2
AC × 28
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 02_hand_00.txt, 02_hand_01.txt, 02_hand_02.txt, 02_hand_03.txt, 02_hand_04.txt, 02_hand_05.txt, 02_hand_06.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3556 KiB
00_sample_01.txt AC 1 ms 3356 KiB
01_random_00.txt AC 1 ms 3464 KiB
01_random_01.txt AC 1 ms 3360 KiB
01_random_02.txt AC 1 ms 3360 KiB
01_random_03.txt AC 1 ms 3520 KiB
01_random_04.txt AC 1 ms 3436 KiB
01_random_05.txt AC 1 ms 3560 KiB
01_random_06.txt AC 1 ms 3472 KiB
01_random_07.txt AC 1 ms 3488 KiB
01_random_08.txt AC 1 ms 3496 KiB
01_random_09.txt AC 1 ms 3568 KiB
01_random_10.txt AC 1 ms 3432 KiB
01_random_11.txt AC 1 ms 3424 KiB
01_random_12.txt AC 1 ms 3524 KiB
01_random_13.txt AC 1 ms 3460 KiB
01_random_14.txt AC 1 ms 3648 KiB
01_random_15.txt AC 1 ms 3432 KiB
01_random_16.txt AC 1 ms 3492 KiB
01_random_17.txt AC 1 ms 3556 KiB
01_random_18.txt AC 1 ms 3432 KiB
02_hand_00.txt AC 1 ms 3496 KiB
02_hand_01.txt AC 1 ms 3524 KiB
02_hand_02.txt AC 1 ms 3364 KiB
02_hand_03.txt AC 1 ms 3560 KiB
02_hand_04.txt AC 1 ms 3520 KiB
02_hand_05.txt AC 1 ms 3420 KiB
02_hand_06.txt AC 1 ms 3320 KiB