結果
| 問題 |
No.74 貯金箱の退屈
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-11-21 01:01:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,279 bytes |
| コンパイル時間 | 1,611 ms |
| コンパイル使用メモリ | 158,764 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2025-01-02 19:47:44 |
| 合計ジャッジ時間 | 2,578 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int(i)=0;(i)<(n);++(i))
#define REPEAT(i, k, n) for(int(i)=(k);(i)<((k)+(n));++(i))
class uf_ {
public:
vector<int> node;
uf_(int n) : node(n, -1){;}
void con(int n, int m){
n = root(n); m = root(m); if(n == m) return;
node[n] += node[m]; node[m] = n;
}
bool is_con(int n, int m){ return root(n) == root(m); }
int root(int n){ return (node[n] < 0) ? n : node[n] = root(node[n]); }
int size(int n){ return -node[root(n)]; }
};
bool m[111][111], unit[111];
int num[111];
int main(){
int N;
cin >> N;
int D[101], W[101];
REP(i,N) cin >> D[i];
REP(i,N) cin >> W[i];
uf_ uf(N);
REP(i,N){
int j = (i+D[i]) % N;
int k = (i-D[i]%N+N) % N;
uf.con(j,k);
m[j][k] = m[k][j] = true;
}
REP(i,N){
if(m[i][i]) unit[uf.root(i)] = true;
if(W[i] == 0) num[uf.root(i)]++;
}
REP(i,N){
if(uf.root(i) == i){
if(unit[i]) continue;
if(num[i] % 2 == 0) continue;
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}