結果

問題 No.1650 Moving Coins
ユーザー simansiman
提出日時 2021-08-21 03:01:05
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 404 ms / 2,000 ms
コード長 1,557 bytes
コンパイル時間 3,003 ms
コンパイル使用メモリ 138,860 KB
実行使用メモリ 32,012 KB
最終ジャッジ日時 2024-04-22 12:16:34
合計ジャッジ時間 14,826 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,136 KB
testcase_01 AC 6 ms
11,008 KB
testcase_02 AC 7 ms
11,136 KB
testcase_03 AC 262 ms
13,260 KB
testcase_04 AC 198 ms
13,268 KB
testcase_05 AC 244 ms
13,264 KB
testcase_06 AC 264 ms
13,268 KB
testcase_07 AC 268 ms
13,264 KB
testcase_08 AC 325 ms
13,264 KB
testcase_09 AC 334 ms
13,456 KB
testcase_10 AC 339 ms
13,396 KB
testcase_11 AC 344 ms
13,412 KB
testcase_12 AC 314 ms
13,460 KB
testcase_13 AC 309 ms
13,440 KB
testcase_14 AC 335 ms
13,292 KB
testcase_15 AC 301 ms
13,484 KB
testcase_16 AC 344 ms
13,264 KB
testcase_17 AC 334 ms
13,264 KB
testcase_18 AC 356 ms
13,264 KB
testcase_19 AC 404 ms
32,012 KB
testcase_20 AC 394 ms
13,388 KB
testcase_21 AC 398 ms
22,632 KB
testcase_22 AC 390 ms
13,396 KB
testcase_23 AC 400 ms
13,392 KB
testcase_24 AC 268 ms
13,392 KB
testcase_25 AC 269 ms
13,264 KB
testcase_26 AC 128 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_N = 1000100;
vector<int> A(MAX_N);
vector<int> B(MAX_N);

struct Command {
  int i;
  char direct;

  Command(int i = -1, char direct = '-') {
    this->i = i;
    this->direct = direct;
  }

  string to_s() {
    return to_string(i + 1) + " " + direct;
  }
};

void dfs(int i, vector<bool> &positions, vector<Command> &commands) {
  while (A[i] != B[i]) {
    int a = A[i];

    if (A[i] < B[i]) {
      if (positions[a + 1]) {
        dfs(i + 1, positions, commands);
      } else {
        commands.push_back(Command(i, 'R'));
        positions[a] = false;
        positions[a + 1] = true;
        A[i] += 1;
      }
    } else {
      if (positions[a - 1]) {
        dfs(i + 1, positions, commands);
      } else {
        commands.push_back(Command(i, 'L'));
        positions[a] = false;
        positions[a - 1] = true;
        A[i] -= 1;
      }
    }
  }
}

int main() {
  int N;
  cin >> N;
  vector<bool> positions(MAX_N, false);

  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    positions[A[i]] = true;
  }

  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }

  vector<Command> commands;

  for (int i = 0; i < N; ++i) {
    dfs(i, positions, commands);
  }

  cout << commands.size() << endl;
  for (Command &cmd : commands) {
    cout << cmd.to_s() << endl;
  }

  return 0;
}
0