結果

問題 No.3245 Payment with 8-rep Currency
ユーザー pengin_2000
提出日時 2025-08-23 00:02:00
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 27,340 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-23 00:02:07
合計ジャッジ時間 6,520 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘solve’:
main.c:5:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 |         scanf("%lld", &n);
      |         ^~~~~~~~~~~~~~~~~
main.c: In function ‘main’:
main.c:47:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |         scanf("%d", &t);
      |         ^~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
void solve()
{
	long long int n;
	scanf("%lld", &n);
	if (n % 8 > 0)
	{
		printf("-1\n");
		return;
	}
	n /= 8;
	long long int a, b, c, d, s;
	if (n < 1665)
	{
		for (d = 0; 1111 * d <= n; d++)
		{
			for (c = 0; 1111 * d + 111 * c <= n; c++)
			{
				for (b = 0; 1111 * d + 111 * c + 11 * b <= n; b++)
				{
					a = n - 1111 * d - 111 * c - 11 * b;
					s = a + b + c + d;
					if (2 * a < s && 2 * b < s && 2 * c < s && 2 * d < s)
					{
						printf("%lld %lld %lld %lld\n", a, b, c, d);
						return;
					}
				}
			}
		}
		printf("-1\n");
	}
	else
	{
		d = 0;
		c = 13;
		n -= 111 * 13;
		b = n / 12;
		a = n - 11 * b;
		printf("%lld %lld %lld %lld\n", a, b, c, d);
	}
	return;
}
int main()
{
	int t;
	scanf("%d", &t);
	for (; t > 0; t--)
		solve();
	return 0;
}
0