結果

問題 No.1400 すごろくで世界旅行
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2021-02-21 20:15:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,716 bytes
コンパイル時間 2,847 ms
コンパイル使用メモリ 175,736 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 21:46:20
合計ジャッジ時間 5,376 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.02.21 20:15:26
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

const int MAX_LEN = 50;
struct bitmatrix{
    vector<bitset<MAX_LEN>> bs1;
    vector<bitset<MAX_LEN>> bs2;
    bitmatrix(){
        bs1.resize(MAX_LEN);
        bs2.resize(MAX_LEN);
    }
    void build() {
        for (int i = 0; i < MAX_LEN; i++) {
            for (int j = 0; j < MAX_LEN; j++) {
                if (bs1[i][j]) {
                    bs2[j].set(i);
                }
            }
        }
    }
    bitmatrix operator*=(bitmatrix &bm) {
        bitmatrix ret;
        for (int i = 0; i < MAX_LEN; i++) {
            for (int j = 0; j < MAX_LEN; j++) {
                if ((this->bs1[i] & bm.bs2[j]).any()) {
                    ret.bs1[i].set(j);
                }
            }
        }
        ret.build();
        this->bs1 = ret.bs1;
        this->bs2 = ret.bs2;
        return ret;
    }
};

template<typename T, typename U>
T _pow(T k, U n, T unity = 1) {
    while (n > 0) {
        if (n & 1) {
            unity *= k;
        }
        k *= k;
        n >>= 1;
    }
    return unity;
}
int main() {
    int v;ll d;cin >> v >> d;
    d = min(2LL*v,d);
    bitmatrix bm;
    for (int i = 0; i < v; i++) {
        string s;cin >> s;
        bm.bs1[i] = bitset<MAX_LEN>(s);
        bm.bs1[i] <<= MAX_LEN-v;
    }
    bm.build();
    bitmatrix I;
    for (int i = 0; i < MAX_LEN; i++) {
        I.bs1[i].set(i);
        I.bs2[i].set(i);
    }
    bm = _pow(bm,d,I);
    for (int i = 0; i < v; i++) {
        if (bm.bs1[i].count() != v) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}
0