結果

問題 No.1400 すごろくで世界旅行
ユーザー takelifetimetakelifetime
提出日時 2021-02-26 20:23:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,843 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 170,844 KB
実行使用メモリ 19,524 KB
最終ジャッジ日時 2024-04-10 10:45:39
合計ジャッジ時間 8,066 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 4 ms
6,948 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 7 ms
6,940 KB
testcase_07 AC 10 ms
8,356 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 6 ms
6,940 KB
testcase_11 AC 4 ms
8,156 KB
testcase_12 AC 74 ms
9,524 KB
testcase_13 AC 993 ms
19,524 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vecvec = vector<vec>;
#define endl "\n"
#define rep_0() for (int i = 0;; i++)
#define rep_1(n) for (int _i = 0; _i < (int)(n); _i++)
#define rep_2(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_3(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep_4(i, s, n, d) for (int i = s; i < (int)(n); i+=d)
#define rep_x(x, a, b, c, d, F, ...) F
#define rep(...) rep_x(,##__VA_ARGS__,rep_4(__VA_ARGS__),rep_3(__VA_ARGS__),rep_2(__VA_ARGS__),rep_1(__VA_ARGS__),rep_0(__VA_ARGS__))
#define len(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v))
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define append push_back
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")

int v;
ll d;
bool g[2000][2000], ans[2000][2000];
string edge[2000];

void power(int sz, bool a[][2000], bool b[][2000]) {
    bool res[2000][2000];
    rep(i, sz) rep(j, sz) res[i][j] = false;

    rep(i, sz)
        rep(j, i, sz)
            rep(k, sz)
                if (a[i][k] & b[k][j]) {
                    res[i][j] = res[j][i] = true;
                    break;
                }

    rep(i, sz) rep(j, sz) a[i][j] = res[i][j];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> v >> d;
    rep(i, v) cin >> edge[i];

    rep(i, v)
        rep(j, v) {
            g[i][j] = (edge[i][j] == '1');
            ans[i][j] = (i == j);
        }

    d = min(d, (ll) 2 * v);
    
    while (d) {
        if (d & 1)
            power(v, ans, g);
        power(v, g, g);
        d >>= 1;
    }

    rep(i, v)
        rep(j, v)
            if (!ans[i][j]) {
                puts("No");
                return 0;
            }
    puts("Yes");
}
0