結果

問題 No.1650 Moving Coins
ユーザー polyesterpolyester
提出日時 2021-08-20 23:20:04
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,471 bytes
コンパイル時間 3,706 ms
コンパイル使用メモリ 142,604 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2024-04-22 07:47:18
合計ジャッジ時間 16,648 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,044 KB
testcase_01 AC 3 ms
7,124 KB
testcase_02 AC 3 ms
7,132 KB
testcase_03 WA -
testcase_04 AC 201 ms
6,984 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 341 ms
8,160 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 397 ms
9,472 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 400 ms
8,716 KB
testcase_23 AC 407 ms
8,516 KB
testcase_24 AC 274 ms
7,068 KB
testcase_25 AC 279 ms
7,080 KB
testcase_26 AC 125 ms
8,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for(int i = 0; i < n; i++) {
    cin >> b[i];
  }

  int ans = 0;
  for(int i = 0; i < n; i++) {
    ans += abs(a[i] - b[i]);
  }
  cout << ans << endl;
  vector<int> c(1000005, -1);
  for(int i = 0; i < n; i++) {
    c[a[i]] = i;
  }
  stack<int> st;
  vector<string> s;
  for(int i = 0; i < n; i++) {
    while(abs(a[i] - b[i]) > 0) {
      if(a[i] < b[i]) {
        if(c[a[i] + 1] == -1) {
          cout << i + 1 << " "
               << "R" << endl;
          a[i]++;
        } else {
          st.push(i);
          break;
        }
      } else if(a[i] > b[i]) {
        if(c[a[i] - 1] == -1) {
          cout << i + 1 << " "
               << "L" << endl;
          a[i]--;
        } else {
          st.push(i);
          break;
        }
      }
    }
  }
  while(st.size() > 0) {
    int now = st.top();
    st.pop();
    while(abs(a[now] - b[now]) > 0) {
      if(a[now] < b[now]) {
        cout << now + 1 << " "
             << "R" << endl;
        a[now]++;
      } else {
        cout << now + 1 << " "
             << "L" << endl;
        a[now]--;
      }
    }
  }
  return 0;
}
0