結果

問題 No.1650 Moving Coins
ユーザー hayatenhayaten
提出日時 2021-08-20 22:23:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,357 bytes
コンパイル時間 5,964 ms
コンパイル使用メモリ 280,032 KB
実行使用メモリ 24,576 KB
最終ジャッジ日時 2024-04-22 05:07:31
合計ジャッジ時間 14,577 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 180 ms
14,720 KB
testcase_09 WA -
testcase_10 AC 183 ms
14,848 KB
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 361 ms
24,448 KB
testcase_20 AC 343 ms
24,320 KB
testcase_21 WA -
testcase_22 AC 344 ms
24,320 KB
testcase_23 AC 355 ms
24,448 KB
testcase_24 WA -
testcase_25 AC 29 ms
5,576 KB
testcase_26 AC 322 ms
24,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region Macros
// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (long long i = 0; i < (n); i++)
#define rrep(i, n) for (long long i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define fi first
#define se second
#define popcount(bit) __builtin_popcount(bit)
#define popcountll(bit) __builtin_popcountll(bit)
#define pb push_back
#define eb emplace_back
using namespace std;
using namespace atcoder;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Graph = vector<vector<int>>;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int fx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int fy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
template <typename T>
const auto INF = numeric_limits<T>::max()/2;

int main() {
  int n;
  cin >> n;
  vector<int> A(n), B(n);
  rep(i, n) cin >> A[i];
  rep(i, n) cin >> B[i];
  set<int> st1;
  set<int> st2;
  rep(i, n){
    st1.insert(A[i]);
    st2.insert(B[i]);
  }
  if(n == 1){
    return 0;
  }
  vector<P> ans;
  queue<int> que;
  if(A[0] >= B[0])que.push(0);
  else {
    if(B[0] < A[1]){
      que.push(0);
    }
  }
  if(A[n-1] <= B[n-1])que.push(n-1);
  else{
    if(B[n-1] > A[n-2])que.push(n-1);
  }
  vector<int> used(n);
  while (!que.empty()){
    int d = que.front();
    que.pop();
    if(used[d])continue;
    used[d] = 1;
    st1.erase(A[d]);
    st2.erase(B[d]);
    if(A[d] >= B[d]){
      rep(j, A[d]- B[d]){
        ans.pb({d, 0});
      }
    }else{
      rep(j, B[d]- A[d]){
        ans.pb({d, 1});
      }
    }
    if(d > 0){
      if(*st2.lower_bound(A[d-1]) == B[d-1]){
        que.push(d - 1);
      }
      if(*st1.lower_bound(B[d-1]) == A[d-1]){
        que.push(d - 1);
      }
    }
    if(d < n-1){
      if(*st2.lower_bound(A[d+1]) == B[d+1]){
        que.push(d + 1);
      }
      if(*st1.lower_bound(B[d+1]) == A[d+1]){
        que.push(d + 1);
      }
    }
  }
  cout << ans.size() << endl;
  for (auto [a, b] : ans){
    if(b == 0){
      cout << a + 1 << " L" << endl;
    }else{
      cout << a + 1 << " R" << endl;
    }
  }
}
0