結果

問題 No.74 貯金箱の退屈
ユーザー kurenaifkurenaif
提出日時 2016-06-22 02:05:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,212 bytes
コンパイル時間 901 ms
コンパイル使用メモリ 98,552 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 00:13:20
合計ジャッジ時間 5,217 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 WA -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 1 ms
5,376 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 2 ms
5,376 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <array>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f
#define CLEAR(a) a = decltype(a)()
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define pii pair<int ,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define pi 2*acos(0.0)
#define INFILE() freopen("in.txt","r",stdin)
#define OUTFILE() freopen("out.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FIN std::ifstream cin("D:\input.txt")

class union_find {
private:
	vector<int> par;
	vector<int> rank;
public:

	union_find(int N) {
		par.resize(N);
		rank.resize(N);
		for (int i = 0; i < N; ++i) {
			par[i] = i;
			rank[i] = 0;
		}
	}

	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;

		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}
};


int main(void) {
	int N; cin >> N;
	vector<int> D(N); for (auto &a : D) cin >> a;
	vector<int> W(N); for (auto &a : W) cin >> a;
	union_find uf(N);
	REP(i, N) {
		if ((i + D[i]) % N == (i+N-D[i]) % N) {
			W[i + D[i] % N] = -inf;
		}
		uf.unite((i + D[i]) % N, (i+N-D[i]) % N);
	}

	vector<int> count(N);
	REP(i,N){
		if (W[i] < 0) count[uf.find(i)] += W[i];
		else count[uf.find(i)] += (W[i] == 0);
	}

	bool res = true;
	REP(i, N) {
		if (count[i] < 0) continue;
		if (count[i] % 2 != 0) {
			res = false;
			break;
		}
	}

	cout << (res ? "Yes" : "No") << endl;

	return 0;
}
0