結果

問題 No.1650 Moving Coins
コンテスト
ユーザー bal4u
提出日時 2021-08-24 10:30:54
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,314 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 229 ms
コンパイル使用メモリ 39,500 KB
最終ジャッジ日時 2026-02-22 07:54:38
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// yuki 1650 Moving Coins
// 2021.8.24

#include <stdio.h>

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(int n) { // 非負整数の表示(出力)
	int i; char b[30];

	if (!n) pc('0');
	else {
		//		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
//	pc('\n');
}

int N;
int A[200005], B[200005];
inline static int ABS(int a) { return a >= 0? a: -a; }

void left(int s, int e) {
	int i, k;
	for (i = s; i <= e; ++i) {
		k = A[i]-B[i];
		while (k--) out(i+1), pc(' '), pc('L'), pc('\n');
	}
}

void right(int e, int s) {
	int i, k;
	for (i = e; i >= s; --i) {
		k = B[i]-A[i];
		while (k--) out(i+1), pc(' '), pc('R'), pc('\n');
	}
}

int main()
{
	int i, j, ans = 0;

	N = in();
	for (i = 0; i < N; ++i) A[i] = in();
	for (i = 0; i < N; ++i) {
		B[i] = in();
		ans += ABS(A[i]-B[i]);
	}
	out(ans), pc('\n');
	if (ans == 0) return 0;
	
	i = 0; while (i < N) {
		if (A[i] == B[i]) ++i;
		else {
			j = i+1;
			if (B[i] < A[i]) {
				while (j < N && B[j] <= A[j]) j++;
				left(i, j-1);
			} else {
				while (j < N && A[j] <= B[j]) j++;
				right(j-1, i);
			}
			i = j;
		}
	}
	return 0;
}
0