結果

問題 No.1400 すごろくで世界旅行
ユーザー milanis48663220milanis48663220
提出日時 2021-02-19 22:56:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,594 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 105,352 KB
実行使用メモリ 11,140 KB
最終ジャッジ日時 2023-10-15 04:09:49
合計ジャッジ時間 8,255 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 25 ms
4,352 KB
testcase_04 AC 7 ms
4,356 KB
testcase_05 AC 8 ms
4,352 KB
testcase_06 AC 109 ms
4,352 KB
testcase_07 AC 163 ms
4,352 KB
testcase_08 AC 31 ms
4,352 KB
testcase_09 AC 25 ms
4,352 KB
testcase_10 AC 56 ms
4,352 KB
testcase_11 AC 18 ms
4,348 KB
testcase_12 AC 696 ms
4,372 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

using bits = bitset<2000>;
// using bits = bitset<20>;

struct matrix{
    int n, m;
    vector<bits> dat;
    matrix(int n_, int m_){
        n = n_; m = m_;
        for(int i = 0; i < n; i++){
            dat.push_back(bits());
        }
    }
    bits& operator[](int x) {
        return dat[x];
	}
};

bool prod(matrix a, matrix b, matrix &ans){
    assert(a.m == b.n);
    for(int i = 0; i < a.n; i++){
        ans[i] = bits();
        for(int j = 0; j < b.m; j++){
            if((a[i]&b[j]).count() > 0) {
                ans[i][j] = 1;
            }
        }
    }
    return true;
}

void copy_mat(matrix a, matrix &b){
    assert(a.n == b.n);
    assert(a.m == b.m);
    for(int i = 0; i < a.n; i++){
        for(int j = 0; j < a.m; j++){
            b.dat[i][j] = a.dat[i][j];
        }
    }
}

void pow_mat(matrix a, ll n, matrix &ans){
    assert(n < ((ll)1<<14));
    matrix buf(a.n, a.n);
    matrix tmp(a.n, a.n);
    copy_mat(a, tmp);

    for(int i = 0; i < a.n; i++) {
        for(int j = 0; j < a.n; j++){
            ans.dat[i][j] = 0;
        }
        ans.dat[i][i] = 1;
    }
    
    for(int i = 0; i <= 11; i++){
        ll m = (ll)1 << i;
        if(m&n){
            prod(tmp, ans, buf);
            copy_mat(buf, ans);
        }
        prod(tmp, tmp, buf);
        copy_mat(buf, tmp);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int v; ll d; cin >> v >> d;
    d = min((ll)v, d);
    matrix e(v, v), p(v, v);
    for(int i = 0; i < v; i++) cin >> e[i];
    // prod(e, e, p);
    pow_mat(e, d, p);

    // for(int i = 0; i < v; i++){
    //     for(int j = 0; j < v; j++) cout << p[i][j];
    //     cout << endl;
    // }
    // for(int i = 0; i < v; i++) cout << p[i] << endl;
    for(int i = 0; i < v; i++){
        for(int j = 0; j < v; j++){
            if(p[i][j] == 0) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
       
}
0