結果

問題 No.1400 すごろくで世界旅行
ユーザー N_N_MochiN_N_Mochi
提出日時 2021-02-19 22:53:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,372 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 180,600 KB
実行使用メモリ 242,428 KB
最終ジャッジ日時 2023-10-15 04:03:29
合計ジャッジ時間 14,593 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 357 ms
226,692 KB
testcase_01 AC 358 ms
222,416 KB
testcase_02 AC 354 ms
222,544 KB
testcase_03 AC 356 ms
222,560 KB
testcase_04 AC 361 ms
222,404 KB
testcase_05 AC 355 ms
222,360 KB
testcase_06 AC 361 ms
222,368 KB
testcase_07 AC 371 ms
222,652 KB
testcase_08 AC 357 ms
222,396 KB
testcase_09 AC 357 ms
222,352 KB
testcase_10 AC 359 ms
222,556 KB
testcase_11 AC 357 ms
222,344 KB
testcase_12 AC 440 ms
222,836 KB
testcase_13 AC 394 ms
242,428 KB
testcase_14 AC 493 ms
226,816 KB
testcase_15 WA -
testcase_16 AC 370 ms
226,704 KB
testcase_17 AC 396 ms
242,424 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(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rrep(i, a) rFOR(i, a, 0)
#define all(c) begin(c),end(c)
using namespace std;
typedef pair<int,int> 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 int INF = 1e9;
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 int MXV = 2000;
vector<int> G[MXV];
vector<vector<vector<int>>> d(MXV,vector<vector<int>>(MXV, vector<int>(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;
        rep(k,G[V].size()){
            int to = G[V][k];
            if(d[i][to][1^sig] == INF){
                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;
        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