$N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks…
- User
sages are sitting around a round table with seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation.
- If sage is right-handed and a left-handed sage sits on his right, a level of frustration occurs to him. A right-handed sage on his right does not cause such frustration at all.
- If sage is left-handed and a right-handed sage sits on his left, a level of frustration occurs to him. A left-handed sage on his left does not cause such frustration at all.
Assistant
pythonimport itertools n = int(input()) a = list(map(int, input().split())) w = list(map(int, input().split())) min_total = float('inf') # Generate permutations of the remaining elements and prepend 0 elements = list(range(1, n)) for perm_part in itertools.permutations(elements): perm = (0,) + perm_part total = 0 for i in range(n): sage_idx = perm[i] current_a = a[sage_idx] current_w = w[sage_idx] if current_a == 0: right_sage_idx = perm[(i + 1) % n] if a[right_sage_idx] == 1: total += current_w else: left_sage_idx = perm[(i - 1) % n] if a[left_sage_idx] == 0: total += current_w if total < min_total: min_total = total print(min_total)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.