結果

問題 No.1650 Moving Coins
ユーザー soldraysoldray
提出日時 2021-08-22 02:42:50
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 388 ms / 2,000 ms
コード長 847 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 123,776 KB
実行使用メモリ 19,516 KB
最終ジャッジ日時 2024-04-23 17:11:46
合計ジャッジ時間 11,622 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 232 ms
6,940 KB
testcase_04 AC 178 ms
6,944 KB
testcase_05 AC 227 ms
6,944 KB
testcase_06 AC 259 ms
6,940 KB
testcase_07 AC 242 ms
6,944 KB
testcase_08 AC 307 ms
6,940 KB
testcase_09 AC 307 ms
6,940 KB
testcase_10 AC 309 ms
6,940 KB
testcase_11 AC 302 ms
6,940 KB
testcase_12 AC 281 ms
6,940 KB
testcase_13 AC 291 ms
6,940 KB
testcase_14 AC 309 ms
6,944 KB
testcase_15 AC 273 ms
6,944 KB
testcase_16 AC 311 ms
6,944 KB
testcase_17 AC 314 ms
6,944 KB
testcase_18 AC 342 ms
6,944 KB
testcase_19 AC 357 ms
19,516 KB
testcase_20 AC 373 ms
6,944 KB
testcase_21 AC 366 ms
13,268 KB
testcase_22 AC 388 ms
6,940 KB
testcase_23 AC 359 ms
6,944 KB
testcase_24 AC 250 ms
6,944 KB
testcase_25 AC 245 ms
6,940 KB
testcase_26 AC 109 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

#define P pair<int, char>

int N;
vector<int> A, B;
vector<P> op;

void dfs(int a) {
  if (A[a] >= B[a]) {
    for (int i = 0; i < A[a] - B[a]; i++) {
      op.push_back(make_pair(a, 'L'));
    }

    A[a] = B[a];

    return;
  }

  if (a < N - 1) {
    dfs(a + 1);
  }

  for (int i = 0; i < B[a] - A[a]; i++) {
    op.push_back(make_pair(a, 'R'));
  }

  A[a] = B[a];
}

int main() {
  cin >> N;

  A.resize(N, 0);
  B.resize(N, 0);

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

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

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

  cout << op.size() << endl;

  for (int i = 0; i < (int)op.size(); i++) {
    cout << (op[i].first + 1) << " " << op[i].second << endl;
  }

  return 0;
}
0