結果

問題 No.74 貯金箱の退屈
ユーザー otoshigootoshigo
提出日時 2024-01-27 18:40:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,450 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 87,856 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-27 18:40:53
合計ジャッジ時間 2,497 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin>>N;
    vector<int>D(N);
    for(int i=0;i<N;i++)cin>>D[i];
    vector<int>W(N);
    for(int i=0;i<N;i++)cin>>W[i];
    vector<vector<int>>G(N);
    vector<bool>check(N);
    for(int i=0;i<N;i++){
        int u=(i+D[i])%N;
        int v=(i-D[i]%N+N)%N;
        if(u==v)check[u]=true;
        else{
            G[u].push_back(v);
            G[v].push_back(u);
        }
    }
    vector<bool>flag(N);
    for(int i=0;i<N;i++){
        if(flag[i])continue;
        queue<int>q;
        flag[i]=true;
        q.push(i);
        int cnt=0;
        if(W[i]==0)cnt++;
        bool ok=false;
        while(q.size()){
            int x=q.front();
            q.pop();
            for(auto j:G[x]){
                if(flag[j])continue;
                if(check[j])ok=true;
                flag[j]=true;
                q.push(j);
                if(W[j]==0)cnt++;
            }
        }
        if(!ok&&cnt%2==1){
            cout<<"No"<<"\n";
            return 0;
        }
    }
    cout<<"Yes"<<"\n";
}
0