結果

問題 No.1400 すごろくで世界旅行
ユーザー yosswi414yosswi414
提出日時 2021-02-19 02:15:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,179 bytes
コンパイル時間 2,685 ms
コンパイル使用メモリ 213,924 KB
実行使用メモリ 13,604 KB
最終ジャッジ日時 2024-09-15 06:54:13
合計ジャッジ時間 8,327 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 9 ms
5,376 KB
testcase_07 AC 13 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 47 ms
5,376 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// head of mylib.h

#include <bits/stdc++.h>

using ll = long long;
using ull = unsigned long long;
using pi = std::pair<ll, ll>;

#define chmin(x, a) ((x) = std::min({(x), (a)})
#define chmax(x, a) ((x) = std::max({(x), (a)})

template <class T>
class V : public std::vector<T> {
    typedef std::vector<T> vector;

  public:
    using vector::begin;
    using vector::end;
    using vector::operator[];
    using vector::back;
    using vector::clear;
    using vector::const_iterator;
    using vector::empty;
    using vector::erase;
    using vector::front;
    using vector::insert;
    using vector::iterator;
    using vector::pop_back;
    using vector::push_back;
    using vector::rbegin;
    using vector::rend;
    using vector::resize;
    using vector::size;
    using vector::vector;

    ll sum() const {
        ll x = 0;
        std::cout << "sum()" << std::endl;
        return x;
    }
    ll max() const {
        ll x = std::numeric_limits<ll>::min();
        std::cout << "max()" << std::endl;
        return x;
    }
    ll min() const {
        ll x = std::numeric_limits<ll>::max();
        std::cout << "min()" << std::endl;
        return x;
    }
};

template <class T>
using VV = V<V<T>>;

template <class T>
std::ostream& operator<<(std::ostream& os, const V<T>& v) {
    for (auto itr = v.begin(); itr != v.end();++itr)
        os << (itr != v.begin() ? " " : "") << *itr;
    os << std::endl;
    return os;
}
template <class T>
std::istream& operator>>(std::istream& is, V<T>& v) {
    for (auto& i : v) is >> i;
    return is;
}

void fin(const char* str){
    std::cout << str << std::endl;
    exit(0);
}

// end of mylib.h

using namespace std;

#define MAX_LEN 1000
using bs = bitset<MAX_LEN>;

V<bs> prod(const V<bs>& A, const V<bs>& B, bool counted = false) {
    int v = A.size();
    V<bs> X(v);
    for (int i = 0; i < v; ++i) {
        for (int j = A[i]._Find_first(); j < v; j = A[i]._Find_next(j)) {
            X[i] |= B[j];
        }
    }
    // if (!counted) {
    //     int na = 0, nb = 0;
    //     for (int i = 0; i < v; ++i) {
    //         na += A[i].count();
    //         nb += B[i].count();
    //         if (na > nb) return prod(B, A, true);
    //     }
    // }

    // for (int i = 0; i < v; ++i) {
    //     for (int j = 0; j < v; ++j) {
    //         for (int k = A[i]._Find_first(); k < v; k = A[i]._Find_next(k)) {
    //             if(B[k][j]){
    //                 X[i].set(j);
    //                 break;
    //             }
    //         }
    //     }
    // }
    return X;
};

int doubling() {
    ll v, d;
    cin >> v >> d;
    d = min(d, v * 2ll);
    V<bs> E(v);
    for (auto& i : E) {
        string str;
        cin >> str;
        reverse(str.begin(), str.end());
        i = bs(str);
    }
    const int pwrdp = 11; // 2^11 > 2V > 2^10
    VV<bs> dp(pwrdp, V<bs>(v));
    dp[0] = E;

    for (int i = 1; i < pwrdp; ++i) {
        dp[i] = prod(dp[i - 1], dp[i - 1]);
    }

    V<bs> Rchbl(v);
    for (int i = 0; i < v; ++i) Rchbl[i].set(i);
    
    for (int di = 0, dd = d; dd > 0; ++di, dd /= 2) {
        if (dd & 1) Rchbl = prod(Rchbl, dp[di]);
    }
    
    for (int i = 0; i < v; ++i)
        if ((ll)Rchbl[i].count() < v) return cout << "No" << endl, 0;
    cout << "Yes" << endl;
    return 0;
}

int normal() {
    int v, d;
    cin >> v >> d;
    d = min(d, v * 2);
    using bs = bitset<MAX_LEN>;
    V<bs> E(v);
    for (auto& i : E) {
        string str;
        cin >> str;
        reverse(str.begin(), str.end());
        i = bs(str);
    }
    
    for (int i = 0; i < v; ++i) {
        bs reachable = E[i], back1, back2;
        back1[i] = true;
        // already consumed 1 turn for reachable
        for (int j = 0; j < d - 1; ++j) {
            bs diff = reachable ^ back2;  // back1 ^ back2
            if (diff.none()) break;
            back2 = back1;
            for (int k = diff._Find_first(); k < v; k = diff._Find_next(k))
                back1 |= E[k];
            swap(reachable, back1);
        }
        if ((ll)reachable.count() < v) return cout << "No" << endl, 0;
    }
    cout << "Yes" << endl;
    return 0;
}

int main(){
    doubling();
}
0