結果

問題 No.1400 すごろくで世界旅行
ユーザー kyoprounokyoprouno
提出日時 2021-02-20 00:15:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,688 bytes
コンパイル時間 2,998 ms
コンパイル使用メモリ 222,080 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-17 02:14:12
合計ジャッジ時間 11,220 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 64 ms
4,348 KB
testcase_04 AC 5 ms
4,348 KB
testcase_05 AC 11 ms
4,348 KB
testcase_06 AC 588 ms
5,944 KB
testcase_07 AC 1,528 ms
7,792 KB
testcase_08 AC 81 ms
4,348 KB
testcase_09 AC 69 ms
4,348 KB
testcase_10 AC 207 ms
4,676 KB
testcase_11 AC 52 ms
4,348 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
using vv=vector<vector<ll>>;
const ll MOD=1e9+7;

vv E(int n) //行列の初期化(単位行列)
{
  vv res(n, vector<ll>(n));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      res[i][j] = (i == j); //対角成分を1に、それ以外を0にする。
  return res;
}

vv matprod(vv A, vv B) //行列の掛け算
{
  int l = A.size(), m = B.size(), n = B[0].size();
  vv res(l, vector<ll>(n, 0));
  for (int i = 0; i < l; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < m; k++)
        res[i][j] = (res[i][j] + A[i][k] * B[k][j]) % MOD;
  return res;
}

vv matpow(vv A, ll n) //行列累乗
{
  vv p = A, res = E(A.size());
  while (n > 0)
  {
    if (n & 1)
      res = matprod(res, p);
    p = matprod(p, p);
    n >>= 1;
  }
  return res;
}

int main()
{
  ll m, k;
  cin >> m >> k;
  
  vv tran(m, vector<ll>(m, 0)); //tranは写像f:A(m)→A(m)を表す行列
  for (int i = 0; i < m; i++)
    for (int t = 0; t < m; t++)
    {
      char c;
      cin >> c;
      ll num=c-'0';
      tran[i][t]=num;
    }
  tran = matpow(tran, k);
  bool ok=true;
  rep(i,m){
      rep(j,m){
          if(tran[i][j]==0) ok=false;
      }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}
0