結果
| 問題 |
No.1650 Moving Coins
|
| コンテスト | |
| ユーザー |
hayaten
|
| 提出日時 | 2021-08-20 22:38:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,620 bytes |
| コンパイル時間 | 5,171 ms |
| コンパイル使用メモリ | 283,024 KB |
| 最終ジャッジ日時 | 2025-01-23 23:58:43 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 15 |
ソースコード
#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]);
st1.insert(B[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(st2.empty())break;
if(d > 0){
if(*st2.lower_bound(A[d-1]) == B[d-1]){
que.push(d - 1);
}
if(*st2.rbegin() == B[d-1]){
que.push(d - 1);
}
if(*st1.lower_bound(B[d-1]) == A[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);
}
if(*st2.rbegin() == B[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;
}
}
}
hayaten