結果

問題 No.74 貯金箱の退屈
ユーザー krotonkroton
提出日時 2014-11-08 18:31:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,492 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 67,060 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 02:44:57
合計ジャッジ時間 3,071 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

typedef vector<int> vec;
typedef vector<vec> mat;

bool check(mat A, vec b){
    const int M = (int)A.size();
    const int N = (int)A[0].size();
    
    vector<bool> used(M, false);
    for(int j=0;j<N;j++){
        int p = -1;
        for(int i=0;i<M;i++)if(!used[i] && A[i][j] == 1){
            p = i;
            break;
        }
        if(p == -1)continue;
        
        used[p] = true;
        for(int k=0;k<M;k++)if(!used[k]){
            int c = A[k][j];
            
            for(int l=0;l<N;l++){
                A[k][l] = (A[k][l] - A[p][l] * c + 2) % 2;
            }
            
            b[k] = (b[k] - b[p] * c + 2) % 2;
        }
    }
    
    for(int i=0;i<M;i++){
        if(!used[i] && b[i] != 0){
            return false;
        }
    }
    
    return true;
}

string solve(int N, vector<int> D, vector<int> W){
    mat A(N, vec(N, 0));
    for(int i=0;i<N;i++){
        int L = (i - D[i] % N + N) % N;
        int R = (i + D[i]) % N;
        
        A[L][i] = 1;
        A[R][i] = 1;
    }
    vec b(N);
    for(int i=0;i<N;i++)b[i] = 1 - W[i];
    
    return check(A, b) ? "Yes" : "No";
}

int main(){
    int N;
    cin >> N;
    
    vector<int> D(N), W(N);
    for(int i=0;i<N;i++){
        cin >> D[i];
    }
    for(int i=0;i<N;i++){
        cin >> W[i];
    }
    
    cout << solve(N, D, W) << endl;
    return 0;
}
0