結果

問題 No.1650 Moving Coins
ユーザー polyesterpolyester
提出日時 2021-08-20 23:30:19
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 1,565 bytes
コンパイル時間 4,728 ms
コンパイル使用メモリ 140,576 KB
実行使用メモリ 9,456 KB
最終ジャッジ日時 2024-04-22 08:06:14
合計ジャッジ時間 16,698 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,040 KB
testcase_01 AC 4 ms
7,168 KB
testcase_02 AC 4 ms
7,168 KB
testcase_03 AC 269 ms
7,168 KB
testcase_04 AC 205 ms
7,156 KB
testcase_05 AC 248 ms
7,040 KB
testcase_06 AC 282 ms
7,156 KB
testcase_07 AC 280 ms
7,040 KB
testcase_08 AC 341 ms
7,808 KB
testcase_09 AC 345 ms
8,160 KB
testcase_10 AC 347 ms
8,064 KB
testcase_11 AC 354 ms
8,180 KB
testcase_12 AC 323 ms
7,552 KB
testcase_13 AC 322 ms
7,808 KB
testcase_14 AC 343 ms
7,928 KB
testcase_15 AC 315 ms
7,552 KB
testcase_16 AC 356 ms
8,092 KB
testcase_17 AC 342 ms
8,176 KB
testcase_18 AC 370 ms
8,448 KB
testcase_19 AC 398 ms
9,456 KB
testcase_20 AC 403 ms
8,576 KB
testcase_21 AC 402 ms
8,960 KB
testcase_22 AC 405 ms
8,584 KB
testcase_23 AC 407 ms
8,624 KB
testcase_24 AC 280 ms
6,980 KB
testcase_25 AC 274 ms
7,040 KB
testcase_26 AC 128 ms
8,704 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;
          c[a[i]] = -1;
          a[i]++;
          c[a[i]] = i;
        } else {
          st.push(i);
          break;
        }
      } else if(a[i] > b[i]) {
        if(c[a[i] - 1] == -1) {
          cout << i + 1 << " "
               << "L" << endl;
          c[a[i]] = -1;
          a[i]--;
          c[a[i]] = 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