結果

問題 No.1650 Moving Coins
ユーザー pengin_2000pengin_2000
提出日時 2021-08-20 21:51:48
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,075 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 31,616 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-22 04:20:57
合計ジャッジ時間 4,903 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 16 ms
5,376 KB
testcase_04 AC 12 ms
5,376 KB
testcase_05 AC 15 ms
5,376 KB
testcase_06 AC 16 ms
5,376 KB
testcase_07 AC 16 ms
5,376 KB
testcase_08 AC 40 ms
5,376 KB
testcase_09 AC 39 ms
5,376 KB
testcase_10 AC 69 ms
5,376 KB
testcase_11 AC 41 ms
5,376 KB
testcase_12 AC 31 ms
5,376 KB
testcase_13 AC 32 ms
5,376 KB
testcase_14 AC 39 ms
5,376 KB
testcase_15 AC 27 ms
5,376 KB
testcase_16 AC 47 ms
5,376 KB
testcase_17 AC 45 ms
5,376 KB
testcase_18 AC 50 ms
5,376 KB
testcase_19 AC 60 ms
5,376 KB
testcase_20 AC 60 ms
5,376 KB
testcase_21 AC 60 ms
5,376 KB
testcase_22 AC 62 ms
5,760 KB
testcase_23 AC 61 ms
5,760 KB
testcase_24 AC 16 ms
5,376 KB
testcase_25 AC 16 ms
5,376 KB
testcase_26 AC 44 ms
5,760 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:2:15: warning: conflicting types for built-in function 'abs'; expected 'int(int)' [-Wbuiltin-declaration-mismatch]
    2 | long long int abs(long long int n)
      |               ^~~
main.c:2:1: note: 'abs' is declared in header '<stdlib.h>'
    1 | #include<stdio.h>
  +++ |+#include <stdlib.h>
    2 | long long int abs(long long int n)

ソースコード

diff #

#include<stdio.h>
long long int abs(long long int n)
{
	if (n < 0)
		n *= -1;
	return n;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	long long int a[200005], b[200005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	for (i = 0; i < n; i++)
		scanf("%lld", &b[i]);
	long long int cnt = 0;
	for (i = 0; i < n; i++)
		cnt += abs(a[i] - b[i]);
	printf("%lld\n", cnt);
	int c[200005], cc = 0;
	for (i = 0; i < n; i++)
	{
		if (a[i] < b[i])
		{
			if (i == n - 1)
			{
				c[cc] = i;
				cc++;
			}
			else if (b[i] < a[i + 1])
			{
				c[cc] = i;
				cc++;
			}
		}
		else
		{
			if (i == 0)
			{
				c[cc] = i;
				cc++;
			}
			else if (a[i - 1] < b[i])
			{
				c[cc] = i;
				cc++;
			}
		}
	}
	while (cc > 0)
	{
		cc--;
		i = c[cc];
		while (a[i] < b[i])
		{
			printf("%d R\n", i + 1);
			a[i]++;
		}
		while (a[i] > b[i])
		{
			printf("%d L\n", i + 1);
			a[i]--;
		}
		if (i > 0)
		{
			if (a[i - 1] < b[i - 1])
			{
				c[cc] = i - 1;
				cc++;
			}
		}
		if (i < n - 1)
		{
			if (b[i + 1] < a[i + 1])
			{
				c[cc] = i + 1;
				cc++;
			}
		}
	}
	return 0;
}
0