結果
問題 | No.74 貯金箱の退屈 |
ユーザー | ckawatak |
提出日時 | 2018-12-23 12:54:18 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 31 ms / 5,000 ms |
コード長 | 1,309 bytes |
コンパイル時間 | 89 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-09-25 10:31:15 |
合計ジャッジ時間 | 2,124 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
N = int(input()) D = list(map(int, input().split(' '))) W = list(map(int, input().split(' '))) def unite(n, graphs, pairs): if n == len(pairs): return graphs pair = pairs[n] united_graph = {} new_graphs = [] for graph in graphs: if pair[0] in graph or pair[1] in graph: united_graph.update(graph) else: new_graphs.append(graph) united_graph.update({pair[0]:1, pair[1]:1}) # flag to indicate that the same coin is flipped if pair[0] == pair[1]: united_graph[N] = 1 new_graphs.append(united_graph) return unite(n+1, new_graphs, pairs) normalized = [] for d in D: normalized.append(d % N) # find coins to be flipped pairs = [] for i,n in enumerate(normalized): pairs.append( ( (i + n + N) % N, (i - n + N) % N ) ) indices = [0 for _ in range(N)] for pair in pairs: indices[pair[0]] = 1 indices[pair[1]] = 1 # find coins not to be flipped and 0 for i in range(N): if indices[i] == 0 and W[i] == 0: print('No') exit(0) graphs = unite(0, [], pairs) for graph in graphs: zeros = 0 for key in graph: if key < N and W[key] == 0: zeros = zeros + 1 if zeros % 2 != 0 and N not in graph: print('No') exit(0) print('Yes')