結果

問題 No.1650 Moving Coins
ユーザー pengin_2000pengin_2000
提出日時 2021-08-20 21:51:48
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,075 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 29,768 KB
実行使用メモリ 5,700 KB
最終ジャッジ日時 2023-08-04 06:14:33
合計ジャッジ時間 5,120 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 16 ms
4,380 KB
testcase_04 AC 11 ms
4,380 KB
testcase_05 AC 14 ms
4,384 KB
testcase_06 AC 15 ms
4,384 KB
testcase_07 AC 15 ms
4,376 KB
testcase_08 AC 40 ms
4,700 KB
testcase_09 AC 40 ms
4,380 KB
testcase_10 AC 46 ms
4,656 KB
testcase_11 AC 43 ms
4,380 KB
testcase_12 AC 32 ms
4,384 KB
testcase_13 AC 31 ms
4,376 KB
testcase_14 AC 40 ms
4,500 KB
testcase_15 AC 28 ms
4,376 KB
testcase_16 AC 47 ms
4,384 KB
testcase_17 AC 46 ms
4,680 KB
testcase_18 AC 49 ms
4,760 KB
testcase_19 AC 61 ms
4,944 KB
testcase_20 AC 61 ms
4,940 KB
testcase_21 AC 60 ms
4,940 KB
testcase_22 AC 62 ms
5,688 KB
testcase_23 AC 61 ms
5,696 KB
testcase_24 AC 16 ms
4,380 KB
testcase_25 AC 15 ms
4,376 KB
testcase_26 AC 46 ms
5,700 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:2:15: 警告: 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: 備考: ‘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