結果
| 問題 |
No.74 貯金箱の退屈
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-07-22 01:25:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 2,160 bytes |
| コンパイル時間 | 2,083 ms |
| コンパイル使用メモリ | 178,764 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-09 04:41:25 |
| 合計ジャッジ時間 | 2,719 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
#define show(x) cout << #x << " = " << x << endl
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
os << "sz=" << v.size() << "\n[";
for (const auto& p : v) {
os << p << ",";
}
os << "]\n";
return os;
}
template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
os << "(" << p.first << "," << p.second
<< ")";
return os;
}
constexpr ll MOD = 1e9 + 7;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;
struct Graph {
Graph(int n)
{
edge.resize(n);
}
void addEdge(int from, int to)
{
edge[from].push_back(to);
edge[to].push_back(from);
}
void print()
{
show(edge);
}
vector<vector<int>> edge;
};
int main()
{
int N;
cin >> N;
Graph g(N);
for (ll i = 0; i < N; i++) {
int d;
cin >> d;
const int s1 = (i + N - (d % N)) % N;
const int s2 = (i + (d % N)) % N;
g.addEdge(s1, s2);
}
vector<bool> side(N);
for (ll i = 0; i < N; i++) {
bool w;
cin >> w;
side[i] = w;
}
vector<bool> checked(N, false);
for (int i = 0; i < N; i++) {
if (not checked[i]) {
queue<int> q;
q.push(i);
checked[i] = true;
int s[2] = {0, 0};
bool flag = false;
while (not q.empty()) {
const int p = q.front();
q.pop();
s[side[p]]++;
for (const int to : g.edge[p]) {
if (to == p) {
flag = true;
}
if (not checked[to]) {
q.push(to);
checked[to] = true;
}
}
}
if ((not flag) and s[0] % 2 == 1) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
}