結果

問題 No.1650 Moving Coins
ユーザー bonKotsu
提出日時 2022-07-18 13:22:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,174 bytes
コンパイル時間 3,878 ms
コンパイル使用メモリ 254,536 KB
最終ジャッジ日時 2025-01-30 10:49:17
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define LP pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
template<class T>
void chmax(T& a, T b) { a = max(a, b); };
template<class T>
void chmin(T& a, T b) { a = min(a, b); };


int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), d(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  vector<pair<int, char>> ans;
  rep(i,n) {
    if (a[i] < b[i]) d[i] = 1;
    else if (a[i] > b[i]) d[i] = -1;
  }
  rep(i,n) {
    // left
    if (d[i] == -1) { 
      rep(j,a[i]-b[i]) {
        ans.pb({i+1, 'L'});
      }
    } else if (d[i] == 1) {
      int l = i;
      int r = i;
      while (r+1<n && d[r+1] == 1) {
        r++;
      }
      for (int j = r; j >= l; j--) {
        rep(k,b[j]-a[j]) {
          ans.pb({j+1, 'R'});
        }
      }
      i = r;
    }
  }
  cout << ans.size() << endl;
  for (auto [n, c] : ans) cout << n << " " << c << "\n";  

  
}
0