結果
| 問題 |
No.1650 Moving Coins
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-08-21 03:01:05 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 398 ms / 2,000 ms |
| コード長 | 1,557 bytes |
| コンパイル時間 | 3,702 ms |
| コンパイル使用メモリ | 143,256 KB |
| 実行使用メモリ | 32,008 KB |
| 最終ジャッジ日時 | 2024-10-14 11:39:42 |
| 合計ジャッジ時間 | 15,337 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
const int MAX_N = 1000100;
vector<int> A(MAX_N);
vector<int> B(MAX_N);
struct Command {
int i;
char direct;
Command(int i = -1, char direct = '-') {
this->i = i;
this->direct = direct;
}
string to_s() {
return to_string(i + 1) + " " + direct;
}
};
void dfs(int i, vector<bool> &positions, vector<Command> &commands) {
while (A[i] != B[i]) {
int a = A[i];
if (A[i] < B[i]) {
if (positions[a + 1]) {
dfs(i + 1, positions, commands);
} else {
commands.push_back(Command(i, 'R'));
positions[a] = false;
positions[a + 1] = true;
A[i] += 1;
}
} else {
if (positions[a - 1]) {
dfs(i + 1, positions, commands);
} else {
commands.push_back(Command(i, 'L'));
positions[a] = false;
positions[a - 1] = true;
A[i] -= 1;
}
}
}
}
int main() {
int N;
cin >> N;
vector<bool> positions(MAX_N, false);
for (int i = 0; i < N; ++i) {
cin >> A[i];
positions[A[i]] = true;
}
for (int i = 0; i < N; ++i) {
cin >> B[i];
}
vector<Command> commands;
for (int i = 0; i < N; ++i) {
dfs(i, positions, commands);
}
cout << commands.size() << endl;
for (Command &cmd : commands) {
cout << cmd.to_s() << endl;
}
return 0;
}
siman