結果

問題 No.2746 Bicolor Pyramid
ユーザー shobonvipshobonvip
提出日時 2024-04-21 06:55:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,110 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 82,340 KB
実行使用メモリ 63,068 KB
最終ジャッジ日時 2024-04-21 06:55:45
合計ジャッジ時間 4,550 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def var_calc(n):
	var = 0
	for i in range(1, n + 1):
		var += i * i
	return var

def shirabe(n):
	var = 0
	for i in range(1, n + 1):
		var += i * i
	a = [0] * (var + 1)
	a[0] = 1
	for i in range(1, n + 1):
		b = a[::]
		for j in range(var + 1):
			if i * i + j <= var and a[j]:
				b[i * i + j] = 1
		a = b
	tar = []
	for i in range(var + 1):
		if a[i] == 0:
			tar.append(i)
	return tar

	
# 1 + 4 + 9 + 16 + 25 + 36


for n in range(1, 11):
	print(n, shirabe(n), var_calc(n))

umekomi = [2, 3, 6, 7, 8, 11, 12, 15, 18, 19, 22, 23, 24, 27, 28, 31, 32, 33, 43, 44, 47, 48, 60, 67,
72, 76, 92, 96, 108, 112, 128]

r, b = map(int,input().split())

ub = 2 * 10 ** 6
lb = 1
while ub - lb > 1:
	t = (ub + lb) // 2
	av = var_calc(t)
	if r + b < av:
		ub = t
		continue
	norep = set(umekomi)
	for i in umekomi:
		norep.add(av - i)
	if r >= av or b >= av:
		lb = t
		continue
	good = 0
	for i in range(0, min(r+1, 10000)):
		if r - i in norep: continue
		if av - (r - i) > b: continue
		if av - (r - i) < 0: continue
		if av - (r - i) in norep: continue
		good = 1
		break
	if good:
		lb = t
	else:
		ub = t

print(lb)
0