結果

問題 No.1400 すごろくで世界旅行
ユーザー milanis48663220milanis48663220
提出日時 2021-02-19 23:05:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,007 ms / 3,153 ms
コード長 2,589 bytes
コンパイル時間 1,380 ms
コンパイル使用メモリ 104,944 KB
実行使用メモリ 6,748 KB
最終ジャッジ日時 2023-10-16 22:15:55
合計ジャッジ時間 14,652 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 7 ms
4,372 KB
testcase_04 AC 3 ms
4,372 KB
testcase_05 AC 3 ms
4,372 KB
testcase_06 AC 21 ms
4,372 KB
testcase_07 AC 30 ms
4,372 KB
testcase_08 AC 8 ms
4,372 KB
testcase_09 AC 7 ms
4,372 KB
testcase_10 AC 13 ms
4,372 KB
testcase_11 AC 6 ms
4,372 KB
testcase_12 AC 124 ms
4,372 KB
testcase_13 AC 1,512 ms
6,748 KB
testcase_14 AC 2,862 ms
6,748 KB
testcase_15 AC 3,007 ms
6,748 KB
testcase_16 AC 1,299 ms
6,748 KB
testcase_17 AC 1,131 ms
6,748 KB
testcase_18 AC 1,927 ms
6,748 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

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]) != 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<<12));
    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 <= 12; 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)2*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