結果

問題 No.1400 すごろくで世界旅行
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2021-02-21 19:53:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,685 bytes
コンパイル時間 1,738 ms
コンパイル使用メモリ 176,168 KB
実行使用メモリ 8,416 KB
最終ジャッジ日時 2023-10-19 21:27:49
合計ジャッジ時間 28,088 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 478 ms
8,412 KB
testcase_01 AC 589 ms
8,412 KB
testcase_02 AC 707 ms
8,412 KB
testcase_03 AC 1,520 ms
8,412 KB
testcase_04 WA -
testcase_05 AC 1,289 ms
8,412 KB
testcase_06 AC 1,517 ms
8,416 KB
testcase_07 AC 1,508 ms
8,416 KB
testcase_08 AC 1,514 ms
8,412 KB
testcase_09 AC 1,634 ms
8,412 KB
testcase_10 AC 1,516 ms
8,416 KB
testcase_11 AC 1,405 ms
8,412 KB
testcase_12 AC 1,774 ms
8,416 KB
testcase_13 AC 1,624 ms
8,416 KB
testcase_14 WA -
testcase_15 AC 2,063 ms
8,416 KB
testcase_16 AC 321 ms
8,344 KB
testcase_17 AC 277 ms
8,344 KB
testcase_18 AC 1,738 ms
8,416 KB
testcase_19 AC 242 ms
8,344 KB
testcase_20 AC 242 ms
8,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.02.21 19:53:36
**/

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

const int MAX_LEN = 2000;
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.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