結果
| 問題 | 
                            No.74 貯金箱の退屈
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ckawatak
                         | 
                    
| 提出日時 | 2018-12-22 23:04:27 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,041 bytes | 
| コンパイル時間 | 97 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 11,008 KB | 
| 最終ジャッジ日時 | 2024-09-25 10:18:17 | 
| 合計ジャッジ時間 | 2,093 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 WA * 2 | 
| other | WA * 1 RE * 29 | 
ソースコード
N = int(input())
D = list(map(int, input().split(' ')))
W = list(map(int, input().split(' ')))
def unite(n, pairs, graphs):
    if n == len(pairs):
        return
    pair = pairs[n]
    indeces = []
    for i,graph in enumerate(graphs):
        if pair[0] in graph or pair[1] in graph:
            indeces.append(i)
    graph = {}
    for i in indeces:
        graph.update(graphs[i])
        graphs.remove(graphs[i])
    graph.update({pair[0]:1, pair[1]:1})
    # flag to indicate that the same coin is flipped
    if pair[0] == pair[1]:
        graph[N] = 1
    graphs.append(graph)
    unite(n+1, pairs, graphs)
    
normalized = []
for d in D:
    normalized.append(d % N)
pairs = []
for i,n in enumerate(normalized):
    pairs.append( ((i + n + N) % N, (i - n + N) % N) )
graphs = []
unite(0, pairs, graphs)
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')
            
            
            
        
            
ckawatak