結果

問題 No.1400 すごろくで世界旅行
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2021-02-21 20:27:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,226 ms / 3,153 ms
コード長 1,722 bytes
コンパイル時間 1,798 ms
コンパイル使用メモリ 176,740 KB
実行使用メモリ 8,424 KB
最終ジャッジ日時 2023-10-19 21:55:37
合計ジャッジ時間 29,999 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 507 ms
8,420 KB
testcase_01 AC 632 ms
8,420 KB
testcase_02 AC 760 ms
8,420 KB
testcase_03 AC 1,628 ms
8,420 KB
testcase_04 AC 879 ms
8,420 KB
testcase_05 AC 1,381 ms
8,420 KB
testcase_06 AC 1,622 ms
8,424 KB
testcase_07 AC 1,622 ms
8,424 KB
testcase_08 AC 1,630 ms
8,420 KB
testcase_09 AC 1,752 ms
8,420 KB
testcase_10 AC 1,626 ms
8,424 KB
testcase_11 AC 1,502 ms
8,420 KB
testcase_12 AC 1,846 ms
8,424 KB
testcase_13 AC 1,584 ms
8,424 KB
testcase_14 AC 2,153 ms
8,424 KB
testcase_15 AC 2,226 ms
8,424 KB
testcase_16 AC 298 ms
8,352 KB
testcase_17 AC 282 ms
8,352 KB
testcase_18 AC 1,952 ms
8,424 KB
testcase_19 AC 259 ms
8,352 KB
testcase_20 AC 259 ms
8,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.02.21 20:27:10
**/

#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;
        reverse(s.begin(), s.end());
        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