Problem Statement Recently, AIs which play Go (a traditional board game) are well…
- User
Problem Statement
Recently, AIs which play Go (a traditional board game) are well investigated. Your friend Hikaru is planning to develop a new awesome Go AI named Sai and promote it to company F or company G in the future. As a first step, Hikaru has decided to develop an AI for 1D-Go, a restricted version of the original Go.
In both of the original Go and 1D-Go, capturing stones is an important strategy. Hikaru asked you to implement one of the functions of capturing.
In 1D-Go, the game board consists of grids lie in a row. A state of 1D-go is described by a string of length . The -th character of describes the -th grid as the following:
Assistant
pythondef is_move_valid(temp_s): n = len(temp_s) i = 0 while i < n: if temp_s[i] != 'W': i += 1 continue start = i while i < n and temp_s[i] == 'W': i += 1 end = i - 1 left = temp_s[start - 1] if start > 0 else None right = temp_s[end + 1] if end < n - 1 else None if left == 'B' and right == 'B': return False return True def count_captured(temp_s): n = len(temp_s) captured = 0 i = 0 while i < n: if temp_s[i] != 'B': i += 1 continue start = i while i < n and temp_s[i] == 'B': i += 1 end = i - 1 left = temp_s[start - 1] if start > 0 else None right = temp_s[end + 1] if end < n - 1 else None if left == 'W' and right == 'W': captured += (end - start + 1) return captured L, S = input().split() L = int(L) max_captured = 0 for i in range(L): if S[i] != '.': continue temp = list(S) temp[i] = 'W' temp_str = ''.join(temp) if not is_move_valid(temp_str): continue current = count_captured(temp_str) if current > max_captured: max_captured = current print(max_captured)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.