結果

問題 No.3245 Payment with 8-rep Currency
コンテスト
ユーザー pengin_2000
提出日時 2025-08-23 00:02:00
言語 C
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 787 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 180 ms
コンパイル使用メモリ 40,000 KB
最終ジャッジ日時 2026-02-22 13:44:17
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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