結果

問題 No.1400 すごろくで世界旅行
ユーザー kyoprounokyoprouno
提出日時 2021-02-20 00:19:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,708 bytes
コンパイル時間 2,627 ms
コンパイル使用メモリ 222,092 KB
実行使用メモリ 7,864 KB
最終ジャッジ日時 2023-10-17 02:30:56
合計ジャッジ時間 9,186 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 18 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 199 ms
6,016 KB
testcase_07 AC 414 ms
7,864 KB
testcase_08 AC 24 ms
4,348 KB
testcase_09 AC 18 ms
4,348 KB
testcase_10 AC 63 ms
4,748 KB
testcase_11 AC 12 ms
4,348 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:17:14: warning: overflow in conversion from 'double' to 'long long int' changes value from '1.0e+19' to '9223372036854775807' [-Woverflow]
   17 | const ll MOD=1e19;
      |              ^~~~

ソースコード

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=1e19;

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] = min((res[i][j] + A[i][k] * B[k][j]),1LL);
  return res;
}

vv matpow(vv A, ll n) //行列累乗
{
  vv p = A, res = E(A.size());
  while (n > 0)
  {
    if (n & 1LL)
      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;
    }
    k=min(k,m);
  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