#include #include #include #include #include void print_state(std::vector const & s){ //std::cout << "print: " << std::endl; for( int i = 0; i < s.size()-1; ++i){ std::cout << s[i] << ","; } std::cout << s.back() << std::endl; } int main() { int n = 0; std::cin >> n; std::vector coins; std::vector init_state(n, 0); for( int i = 0; i < n; ++i ) { int in = 0; std::cin >> in; coins.push_back(in); } for( int i = 0; i < n; ++i ) { int in = 0; std::cin >> in; init_state[i] = in==1; } std::queue> states_q; std::set> states; states_q.push(init_state); bool found = false; int counter = 0; while(!states_q.empty()){ //std::cout << "start" << std::endl; std::vector const s = states_q.front(); int t = 1; for(int i = 0; i < n; ++i ) { t *= s[i]; } if(t==1) { found=true; //states_q.clear(); break; } //auto const r = states.insert(s); states_q.pop(); if(states.find(s)==states.end()) { states.insert(s); //if(r.second){ //知って�?る盤面ではなかっ�? //�?番に盤面を生成してqueueに追�?する for(int i = 0; i < n; ++i) { int const plus = 0+coins[i]%n; int const minus = n+(0-coins[i])%n-1; //std::cout << "plus:" << plus %n << std::endl; //std::cout << "minus:" << minus %n << std::endl; //std::vector s_copy = s; std::vector s_copy(n, 0); s_copy[(0 + coins[i])%n] = (int)!(s_copy[plus%n] == 1); s_copy[n - (0 - coins[i])%n - 1] = (int)!(s_copy[minus%n] == 1); //print_state(s_copy); states_q.push(s_copy); //std::cout << "*******" << i << "************" << std::endl; } //std::cout << "end" << std::endl; } else { continue; } } if(found) std::cout << "Yes" << std::endl; else std::cout << "No" << std::endl; return 0; }