結果

問題 No.1400 すごろくで世界旅行
ユーザー N_N_MochiN_N_Mochi
提出日時 2021-02-19 22:50:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,388 bytes
コンパイル時間 2,475 ms
コンパイル使用メモリ 159,664 KB
実行使用メモリ 258,496 KB
最終ジャッジ日時 2023-10-15 03:56:33
合計ジャッジ時間 15,559 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 359 ms
226,688 KB
testcase_01 AC 358 ms
222,324 KB
testcase_02 AC 358 ms
222,408 KB
testcase_03 AC 360 ms
222,532 KB
testcase_04 AC 358 ms
222,540 KB
testcase_05 AC 359 ms
222,392 KB
testcase_06 AC 367 ms
222,456 KB
testcase_07 AC 375 ms
222,608 KB
testcase_08 AC 359 ms
222,464 KB
testcase_09 AC 360 ms
222,336 KB
testcase_10 AC 364 ms
222,348 KB
testcase_11 AC 364 ms
222,404 KB
testcase_12 AC 446 ms
222,976 KB
testcase_13 AC 416 ms
258,496 KB
testcase_14 AC 549 ms
226,596 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 417 ms
258,404 KB
testcase_18 TLE -
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<string> A(V);
    bool ok=true;
    rep(i,V){
        cin >> A[i];
        rep(j,V) if(A[i][j]=='0') ok=false;
    }
    rep(i,V){
        rep(j,V){
            if(A[i][j]=='1'){
                G[i].push_back(j);
            }
        }
    }
    if(ok){
        cout << "Yes" << endl;
        return 0;
    }
    if(D==1){
        cout << "No" << endl;
    }
    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