結果

問題 No.1400 すごろくで世界旅行
ユーザー N_N_MochiN_N_Mochi
提出日時 2021-02-19 22:46:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,378 bytes
コンパイル時間 2,017 ms
コンパイル使用メモリ 181,608 KB
実行使用メモリ 262,600 KB
最終ジャッジ日時 2023-10-15 03:47:54
合計ジャッジ時間 12,740 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 375 ms
222,508 KB
testcase_01 AC 376 ms
222,412 KB
testcase_02 AC 374 ms
222,484 KB
testcase_03 AC 375 ms
222,340 KB
testcase_04 AC 373 ms
222,504 KB
testcase_05 AC 373 ms
222,344 KB
testcase_06 AC 384 ms
222,412 KB
testcase_07 AC 392 ms
222,484 KB
testcase_08 AC 375 ms
222,412 KB
testcase_09 AC 378 ms
222,344 KB
testcase_10 AC 380 ms
222,432 KB
testcase_11 AC 377 ms
222,556 KB
testcase_12 AC 472 ms
222,992 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
using ll = long long;
using ld = long double;
#define FOR(i, a, b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = (ll)(a - 1); i >= (ll)(b); i--)
#define rrep(i, a) rFOR(i, a, 0)
#define all(c) begin(c),end(c)
using namespace std;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long MXV = 2000;
vl G[MXV];
vector<vvl> d(MXV,vvl(MXV, vl(2,INF)));

//bfsにかえる(dijkstraでいいじゃん)
void dijkstra(int i,int s){
    queue<pair<P,int>> pq;
    d[i][s][0] = 0;
    pair<P,int> q;
    q.first=P(0,s);q.second=0;
    pq.push(q);
    while(pq.size()){
        pair<P,int> p = pq.front();
        pq.pop();
        int V = p.first.second;
        int sig=p.second;
        if(d[i][V][sig] < p.first.first){
            continue;
        }
        rep(k,G[V].size()){
            int to = G[V][k];
            if(d[i][to][1^sig] > d[i][V][sig] + 1){
                d[i][to][1^sig] = d[i][V][sig] + 1;
                pair<P,int> neko;
                neko.first=P(d[i][to][1^sig],to);
                neko.second=1^sig;
                pq.push(neko);
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll V,D;
    cin >> V >> D;
    vector<vector<char>> A(V,vector<char>(V));
    bool ok=true;
    rep(i,V){
        rep(j,V){
            cin >> A[i][j];
            if(A[i][j]=='0') ok=false;
        }
    }
    rep(i,V){
        rep(j,V){
            if(A[i][j]=='1'){
                G[i].push_back(j);
            }
        }
    }
    if(D==1&&(!ok)){
        cout << "No" << endl;
        return 0;
    }
    ll parity=D%2;
    rep(i,V){
        dijkstra(i,i);
        rep(j,V){
            if(d[i][j][parity]>D){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}
0