結果

問題 No.5 数字のブロック
ユーザー dashi_dragonsdashi_dragons
提出日時 2017-02-10 16:39:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,319 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 11,100 KB
実行使用メモリ 16,864 KB
最終ジャッジ日時 2023-08-27 06:52:49
合計ジャッジ時間 7,483 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import sys

def check_range(a,b,x):
	if a > x or b < x:
		sys.exit()

def check_eq(a,b):
	if a != b:
		sys.exit()

def cal_realx(data,list,L):

	realx = list[:]
	
	ans = 0
	length = len(realx)

	for i in range(0,length):
		ans += data[i] * realx[i]

	if len(list) == len(data):
		if ans <= L:
			return realx
		else:
			return []

	
	if ans + data[length] <= L:
		realx.append(1)
		realx = cal_realx(data,realx,L)

	elif ans < L:
		realx.append((L - ans) / data[length])
		realx = cal_realx(data,realx,L)

	else:
		realx.append(0)
		realx = cal_realx(data,realx,L)

	return realx

def check_digit(realx,N):
	
	if len(realx) == 0:
		return True

	for i in range(0,N):
		if realx[i] != int(realx[i]):
			return False
	return True


def cal(data,list,L):

	buf = list[:]
	ans = cal_realx(data,buf,L)

	if check_digit(ans,len(data)) == True:
		
		return ans

	elif len(buf) < len(data):
		buf.append(0)
		ans1 = cal(data,buf,L)
		
		buf.pop()
		buf.append(1)
		ans2 = cal(data,buf,L)

		if ans1.count(1) > ans2.count(1):
			return ans1
		else:
			return ans2
		

L = int(input())
check_range(1,10000,L)

N = int(input())
check_range(1,10000,N)

data = input().split(' ')
check_eq(len(data),N)

for i in range(0,N):
	data[i] = int(data[i])
	check_range(1,L,N)

max = 0
cnt = 0

list = []

print(cal(data,list,L).count(1))

0