結果

問題 No.1400 すごろくで世界旅行
ユーザー fumofumofunifumofumofuni
提出日時 2021-02-20 00:18:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,368 bytes
コンパイル時間 2,055 ms
コンパイル使用メモリ 210,792 KB
実行使用メモリ 45,228 KB
最終ジャッジ日時 2023-10-17 02:29:03
合計ジャッジ時間 9,939 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
6,656 KB
testcase_01 AC 27 ms
7,164 KB
testcase_02 AC 125 ms
17,244 KB
testcase_03 AC 68 ms
11,280 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 66 ms
11,224 KB
testcase_06 AC 76 ms
11,328 KB
testcase_07 AC 93 ms
12,448 KB
testcase_08 AC 69 ms
11,296 KB
testcase_09 AC 88 ms
13,288 KB
testcase_10 AC 71 ms
11,328 KB
testcase_11 AC 93 ms
13,776 KB
testcase_12 AC 137 ms
14,032 KB
testcase_13 AC 1,358 ms
45,184 KB
testcase_14 AC 1,357 ms
45,184 KB
testcase_15 WA -
testcase_16 AC 82 ms
36,472 KB
testcase_17 AC 167 ms
36,472 KB
testcase_18 WA -
testcase_19 AC 13 ms
5,648 KB
testcase_20 AC 12 ms
5,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 2000;

int n,m;

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;
    }
};

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

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    mat<MAX_N> A;
    vvl dp(n,vl(n));
    UnionFind uf(n);
    rep(i,n){
        rep(j,n){
            char c;cin >> c;
            A[i][j]=c-'0';
            if(A[i][j]==1)uf.merge(i,j);
        }
    }
    if(uf.size(0)!=n){
        cout << "No" <<endl;
        return 0;
    }

    if(n>1000)A=pow(A,min(m,10000));
    else A=pow(A,m);
    bool ok=true;
    rep(i,n)rep(j,n)if(A[i][j]==0)ok=false;
    cout << (ok? "Yes":"No") <<endl;
}
0