Problem p02695 (python)

Fixed submission:
def next_array(array):#辞書式に次の配列を与える関数
  s = -1
  for x in array[::-1]:
    if x < M:
      break
    else:
      s -= 1
    #Mより小さい最後の項を取得
  
  if s >= -N:
    array[s] += 1#その項を１増やす
    if s < -1:
      for i in range(s+1,0):#以降の項を全て同じ値に
        array[i] = array[s]

  return array
 
def score(array, rules):#点数計算
  scr = 0
  for rule in rules:
    if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):
      scr += rule[3]
      
  return scr
 
# input
N, M, Q = map(int, input().split())
rules = []
 
for i in range(Q):
  a, b, c, d = map(int, input().split())
  rules.append([a, b, c, d])
  
array = [1] * N
max_scr = 0
 
while True:
  max_scr = max(max_scr, score(array,rules)) 
  if array[0] == M:#全探索完了
    break 
  array = next_array(array)#次の配列へ
    
print(max_scr)

Buggy submission (verdict: Runtime Error):
def next_array(array):#辞書式に次の配列を与える関数
  s = -1
  for x in array[::-1]:
    if x < M:
      break
    else:
      s -= 1
    #Mより小さい最後の項を取得
  
  if s >= -N:
    array[s] += 1#その項を１増やす
    if s < -1:
      for i in range(s+1,0):#以降の項を全て同じ値に
        array[i] = array[s]
        
  return array
 
def score(array, rules):#点数計算
  scr = 0
  for rule in rules:
    if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):
      scr += rule[3]
      
  return scr

# input
N, M, Q = map(int, input().split())
rules = []
for i in range(Q):
  a, b, c, d = map(int, input().split())
  rules.append([a, b, c, d])
    
array　= [1] * N
max_scr = 0
 
while True:
  max_scr = max(max_scr, score(array,rules)) 
  if array[0] == M:#全探索完了
    break 
    array = next_array(array)#次の配列へ
    
print(max_scr)

Buggy submission (verdict: Runtime Error):
def next_array(array):#辞書式に次の配列を与える関数
	s = -1
	for x in array[::-1]:
		if x < M:
			break
		else:
			s -= 1
    #Mより小さい最後の項を取得
    
    if s >= -N:
    	array[s] += 1#その項を１増やす
    	if s < -1:
      		for i in range(s+1,0):#以降の項を全て同じ値に
      			array[i] = array[s]
        
	return array
 
def score(array, rules):#点数計算
	scr = 0
    for rule in rules:
		if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):
    		scr += rule[3]
    return scr
 
 
# input
N, M, Q = map(int, input().split())
rules = []
for i in range(Q):
    a, b, c, d = map(int, input().split())
    rules.append([a, b, c, d])
    
array　= [1] * N
max_scr = 0
 
while True:
	max_scr = max(max_scr, score(array,rules)) 
	if array[0] == M:#全探索完了
		break 
	array = next_array(array)#次の配列へ
    
print(max_scr)

Buggy submission (verdict: Runtime Error):
def next_array(array):#辞書式に次の配列を与える関数
	s = -1
	for x in array[::-1]:
		if x < M:
			break
		else:
			s -= 1
    #Mより小さい最後の項を取得
    
    if s >= -N:
    	array[s] += 1#その項を１増やす
    	if s < -1:
      		for i in range(s+1,0):#以降の項を全て同じ値に
      			array[i] = array[s]
        
	return array
 
def score(array, rules):#点数計算
	scr = 0
	for rule in rules:
    	if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):
        	scr += rule[3]
    return scr
 
 
# input
N, M, Q = map(int, input().split())
rules = []
for i in range(Q):
    a, b, c, d = map(int, input().split())
    rules.append([a, b, c, d])
    
array　= [1] * N
max_scr = 0
 
while True:
	max_scr = max(max_scr, score(array,rules)) 
	if array[0] == M:#全探索完了
		break 
	array = next_array(array)#次の配列へ
    
print(max_scr)

Buggy submission (verdict: Runtime Error):
def next_array(array):#辞書式に次の配列を与える関数
	s = -1
	for x in array[::-1]:
    	if x < M:
        	break
        else:
        	s -= 1
    #Mより小さい最後の項を取得
    
    if s >= -N:
    	array[s] += 1#その項を１増やす
    	if s < -1:
      		for i in range(s+1,0):#以降の項を全て同じ値に
      			array[i] = array[s]
        
	return array
 
def score(array, rules):#点数計算
	scr = 0
	for rule in rules:
    	if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):
        	scr += rule[3]
    return scr
 
 
# input
N, M, Q = map(int, input().split())
rules = []
for i in range(Q):
    a, b, c, d = map(int, input().split())
    rules.append([a, b, c, d])
    
array　= [1] * N
max_scr = 0
 
while True:
	max_scr = max(max_scr, score(array,rules)) 
	if array[0] == M:#全探索完了
		break 
	array = next_array(array)#次の配列へ
    
print(max_scr)

Buggy submission (verdict: Runtime Error):
def next_array(array):#辞書式に次の配列を与える関数
	s = -1
	for x in array[::-1]:
    	if x < M:
        	break
        else:
        	s -= 1
    #Mより小さい最後の項を取得
    
    if s >= -N:
    	array[s] += 1#その項を１増やす
    	if s < -1:
      		for i in range(s+1,0):#以降の項を全て同じ値に
      			array[i] = array[s]
        
	return array
 
def score(array, rules):#点数計算
	scr = 0
	for rule in rules:
    	if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):
        	scr += rule[3]
    return scr
 
 
# input
N, M, Q = map(int, input().split())
rules = []
for i in range(Q):
    a, b, c, d = map(int, input().split())
    rules.append([a, b, c, d])
    
array　= [1] * N
max_scr = 0
 
while True:
	max_scr = max(max_scr, score(array,rules)) 
	if array[0] == M:#全探索完了
		break 
	array = next_array(array)#次の配列へ
    
print(max_scr)

Buggy submission (verdict: Runtime Error):
def next_array(array):#辞書式に次の配列を与える関数
	s = -1
	for x in array[::-1]:
    	if x < M:
        	break
        else:
        	s -= 1
    #Mより小さい最後の項を取得
    
    if s >= -N:
      array[s] += 1#その項を１増やす
      if s < -1:
      	for i in range(s+1,0)#以降の項を全て同じ値に
      		array[i] = array[s]
        
	return array
 
def score(array, rules):#点数計算
	scr = 0
	for rule in rules:
    	if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):
        	scr += rule[3]
    return scr
 
 
# input
N, M, Q = map(int, input().split())
rules = []
for i in range(Q):
    a, b, c, d = map(int, input().split())
    rules.append([a, b, c, d])
    
array　= [1] * N
max_scr = 0
 
while True:
  max_scr = max(max_scr, score(array,rules)) 
  if array[0] == M:#全探索完了
    break 
  array = next_array(array)#次の配列へ

Buggy submission (verdict: Runtime Error):
def next_array(array)#辞書式に次の配列を与える関数
	s = -1
	for x in array[::-1]:
    	if x < M:
        	break
        else:
        	s -= 1
    #Mより小さい最後の項を取得
    
    if s >= -N:#その項を１増やす
      array[s] += 1
      for i in range(s,0)#以降の項を全て同じ値に
      	array[i] = array[s]
        
	return array

def score(array, rules)#点数計算
	scr = 0
	for rule in rules:
    	if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):
        	scr += rule[3]
    return scr


# input
N, M, Q = map(int, input().split())
rules = []
for i in range(Q):
    a, b, c, d = map(int, input().split())
    rules.append([a, b, c, d])
    
array　= [1] * N
max_scr = 0

while True:
  max_scr = max(max_scr, score(array,rules)) 
  if array[0] == M:#全探索完了
    break 
  array = next_array(array)#次の配列へ