PythonでJOI難易度5を埋める #1
考えたこと
一つでも不良品が含まれていると動作しないので、分からないものを調べるには3個中2個は正常なものでないといけない。なので、長さa+b+ca+b+cの配列を用意してそれぞれの商品を対応されて調べればよい。1回のループでは上から順に実験結果(入力の配列)を調べていくだけなので、自身よりも後の実験結果は反映されない。これは2回ループを回せば解決する。
a, b, c = map(int,input().split()) n = int(input()) check_list = [list(map(int,input().split())) for _ in range(n)] ps = [2] * (a+b+c) for _ in range(2): for i in range(n): if check_list[i][-1] == 1: for j in range(3): ps[check_list[i][j]-1] = 1 else: if ps[check_list[i][0]-1] == 1 and ps[check_list[i][1]-1] == 1: ps[check_list[i][2]-1] = 0 elif ps[check_list[i][1]-1] == 1 and ps[check_list[i][2]-1] == 1: ps[check_list[i][0]-1] = 0 elif ps[check_list[i][0]-1] == 1 and ps[check_list[i][2]-1] == 1: ps[check_list[i][1]-1] = 0 for i in range(a+b+c): print(ps[i])