結果

問題 No.1400 すごろくで世界旅行
ユーザー chocoruskchocorusk
提出日時 2021-02-19 21:54:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,829 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 128,920 KB
実行使用メモリ 47,488 KB
最終ジャッジ日時 2023-10-15 01:13:42
合計ジャッジ時間 7,837 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
6,748 KB
testcase_01 AC 35 ms
7,248 KB
testcase_02 AC 164 ms
17,060 KB
testcase_03 AC 87 ms
11,232 KB
testcase_04 AC 47 ms
7,992 KB
testcase_05 AC 87 ms
11,012 KB
testcase_06 AC 93 ms
11,044 KB
testcase_07 AC 112 ms
12,172 KB
testcase_08 AC 87 ms
10,952 KB
testcase_09 AC 115 ms
13,088 KB
testcase_10 AC 90 ms
10,952 KB
testcase_11 AC 120 ms
13,548 KB
testcase_12 AC 147 ms
12,124 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template <int COL_SIZE> class mat {
private:
    // (or, and) の意味での積(正方かつ対称行列に限る(重みなし無向グラフの隣接行列とか))
    mat operator*(const mat& m) const {
        mat ans;
        for(int i = 0; i < COL_SIZE; i++){
            for(int j = 0; j < COL_SIZE; j++){
                if(this->a[i][j] == 0) continue;
                ans.a[i] |= m.a[j];
            }
        }
        return ans;
    }
 
public:
    bitset<COL_SIZE>* a;
    int r;
    // 正方行列の場合
    mat() : mat(COL_SIZE){}
    // 一般の行列の場合
    mat(int row_size) : r(row_size){ a = new bitset<COL_SIZE>[r]; }
    int rank() const {
        int res = 0;
        mat<COL_SIZE> b(r);
        for(int i = 0; i < r; i++) b[i] = a[i];
        for(int i = 0; i < COL_SIZE; i++){
            if(res == r) return res;
            int pivot = res;
            if(!b[pivot][i]){
                for(int j = res + 1; j < r; j++){
                    if(b[j][i]){
                        pivot = j;
                        break;
                    }
                }
                if(!b[pivot][i]) continue;
                swap(b[pivot], b[res]);
            }
            for(int j = res + 1; j < r; j++){
                if(b[j][i]) b[j] ^= b[res];
            }
            res++;
        }
        return res;
    }
    inline const bitset<COL_SIZE>& operator[](size_t index) const {
        return a[index];
    }
    inline bitset<COL_SIZE>& operator[](size_t index){
        return a[index];
    }
    friend mat pow(mat m, long long cnt){
        mat res;
        for(int i = 0; i < COL_SIZE; i++) res[i][i] = 1;
        while(cnt){
            if(cnt & 1){
                res = res * m;
            }
            m = m * m;
            cnt >>= 1;
        }
        return res;
    }
};
int main()
{
    int v; ll d;
    cin>>v>>d;
    mat<2000> e;
    char s[2002];
    for(int i=0; i<v; i++){
        scanf("%s", s);
        for(int j=0; j<v; j++){
            e[i][j]=s[j]-'0';
        }
    }
    auto f=pow(e, d);
    for(int i=0; i<v; i++){
        for(int j=0; j<v; j++){
            if(!f[i][j]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}
0