結果

問題 No.74 貯金箱の退屈
ユーザー h_nosonh_noson
提出日時 2016-06-04 01:16:48
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,126 bytes
コンパイル時間 512 ms
コンパイル使用メモリ 66,296 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 00:13:37
合計ジャッジ時間 4,911 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
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 RE -
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 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
#define INF (int)1e8
#define MOD (int)(1e9+7)

typedef long long ll;

int par[100];

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

void unite(int x, int y) {
    par[find(x)] = find(y);
}

void init(int n) {
    int i;
    rep (i,n) par[i] = i;
}

int main(void) {
    int i, n;
    int d[100], w[100];
    int cnt[100] {};
    cin >> n;
    rep (i,n) cin >> d[i];
    rep (i,n) cin >> w[i];

    init(n);
    rep (i,n) {
        unite((i+d[i])%n,(i-d[i]+n)%n);
    }
    rep (i,n) if ((i+d[i])%n == (i-d[i]+n)%n) cnt[find(i)] = -2;
    rep (i,n) {
        int x = find(i);
        if (cnt[x] < 0) continue;
        cnt[x] += w[i] == 0;
    }
    bool ans = true;
    rep (i,n) ans &= cnt[i] % 2 == 0;
    if (ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}
0