結果
| 問題 |
No.1650 Moving Coins
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-20 21:48:38 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 151 ms / 2,000 ms |
| コード長 | 985 bytes |
| コンパイル時間 | 1,064 ms |
| コンパイル使用メモリ | 118,080 KB |
| 実行使用メモリ | 51,544 KB |
| 最終ジャッジ日時 | 2024-06-22 12:07:14 |
| 合計ジャッジ時間 | 7,884 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
void main() {
auto N = readln.chomp.to!int;
auto A = readln.split.map!(to!int).array;
auto B = readln.split.map!(to!int).array;
int ans = N.iota.map!(i => abs(A[i] - B[i])).sum;
ans.writeln;
void dfs(int i) {
if (i == N) return;
if (A[i] >= B[i]) {
foreach (_; 0..A[i] - B[i]) writeln(i+1, " L");
dfs(i + 1);
} else {
while (i != N - 1 && A[i] < B[i] && A[i] + 1 < A[i + 1]) {
A[i] += 1;
writeln(i + 1, " R");
}
if (A[i] == B[i]) dfs(i + 1);
else {
dfs(i + 1);
while (A[i] < B[i]) {
writeln(i + 1, " R");
A[i] += 1;
}
}
}
}
dfs(0);
}