結果

問題 No.74 貯金箱の退屈
ユーザー assy1028assy1028
提出日時 2016-07-04 23:29:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,548 bytes
コンパイル時間 882 ms
コンパイル使用メモリ 104,280 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 21:57:48
合計ジャッジ時間 1,938 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int N;
int d[110];
bool w[110];

// rank on GF(2)
const int max_n = 110;
int matrix_rank(vector<bitset<max_n> > A, int n) {
    int m = A.size();
    int i, idx = 0;
    for (i = 0; i < m && idx < n; i++, idx++) {
        if (!A[i][idx]) {
            bool f = false;
            int j, k;
            for (j = idx; j < n; j++) {
                for (k = i; k < m; k++) {
                    if (A[k][j]) {
                        f = true;
                        break;
                    }
                }
                if (f) break;
            }
            if (!f) return i;
            swap(A[i], A[k]);
            idx = j;
        }
        for (int j = i+1; j < m; j++) {
            if (A[j][idx])
                A[j] ^= A[i];
        }
    }
    return min(i, idx);
}

bool solve() {
    vector<bitset<max_n> > A(N), Ab(N);
    for (int i = 0; i < N; i++) {
        int a = (i + d[i]) % N;
        int b = (i - d[i] + N) % N;
        if (a == b) {
            A[a][i] = Ab[a][i] = true;
        } else {
            A[a][i] = Ab[a][i] = true;
            A[b][i] = Ab[b][i] = true;
        }
        Ab[i][N] = !w[i];
    }
    return matrix_rank(A, N) == matrix_rank(Ab, N+1);
    return true;
}

void input() {
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> d[i];
    for (int i = 0; i < N; i++)
        cin >> w[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << (solve()?"YES":"NO") << endl;
}
0