結果

問題 No.2746 Bicolor Pyramid
ユーザー shobonvipshobonvip
提出日時 2024-04-21 06:57:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,358 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 82,052 KB
実行使用メモリ 62,864 KB
最終ジャッジ日時 2024-04-21 06:58:02
合計ジャッジ時間 4,780 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
57,392 KB
testcase_01 AC 48 ms
57,920 KB
testcase_02 AC 52 ms
61,072 KB
testcase_03 AC 46 ms
58,808 KB
testcase_04 AC 47 ms
57,528 KB
testcase_05 AC 52 ms
60,956 KB
testcase_06 AC 53 ms
62,864 KB
testcase_07 AC 58 ms
58,532 KB
testcase_08 AC 46 ms
57,980 KB
testcase_09 AC 106 ms
57,396 KB
testcase_10 AC 117 ms
57,816 KB
testcase_11 AC 94 ms
59,364 KB
testcase_12 AC 111 ms
58,400 KB
testcase_13 AC 115 ms
58,660 KB
testcase_14 AC 46 ms
58,556 KB
testcase_15 AC 125 ms
57,640 KB
testcase_16 AC 63 ms
59,252 KB
testcase_17 AC 77 ms
58,224 KB
testcase_18 AC 78 ms
57,696 KB
testcase_19 AC 69 ms
58,000 KB
testcase_20 AC 63 ms
57,816 KB
testcase_21 AC 62 ms
58,804 KB
testcase_22 AC 68 ms
58,232 KB
testcase_23 AC 75 ms
59,380 KB
testcase_24 AC 77 ms
59,384 KB
testcase_25 AC 56 ms
59,144 KB
testcase_26 AC 59 ms
58,196 KB
testcase_27 AC 99 ms
58,252 KB
testcase_28 AC 92 ms
58,128 KB
testcase_29 AC 65 ms
59,204 KB
testcase_30 AC 65 ms
58,544 KB
testcase_31 AC 84 ms
59,364 KB
testcase_32 AC 64 ms
59,896 KB
testcase_33 AC 65 ms
57,880 KB
testcase_34 AC 106 ms
57,660 KB
testcase_35 AC 98 ms
58,296 KB
testcase_36 AC 112 ms
58,184 KB
testcase_37 AC 110 ms
57,936 KB
権限があれば一括ダウンロードができます

ソースコード

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

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
	if t <= 16:
		g = [i * i for i in range(1, t + 1)]
		mode = 0
		for i in range(1 << t):
			at = 0
			bt = 0
			for j in range(t):
				if i >> j & 1:
					at += g[j]
				else:
					bt += g[j]
			if at <= r and bt <= b:
				mode = 1
				break
		if mode:
			lb = t
		else:
			ub = t
	else:		
		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