結果

問題 No.1400 すごろくで世界旅行
ユーザー snow39snow39
提出日時 2021-02-20 16:06:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,808 bytes
コンパイル時間 1,097 ms
コンパイル使用メモリ 100,888 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-17 23:14:33
合計ジャッジ時間 8,384 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 7 ms
4,348 KB
testcase_07 AC 11 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 51 ms
4,348 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N;
  ll D;
  cin>>N>>D;
  vector<string> E(N);
  rep(i,N) cin>>E[i];

  if(N==1){
    if(E[0][0]=='1') cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
  }

  vector<vector<int>> g(N);
  rep(i,N) rep(j,N) if(E[i][j]=='1') g[i].push_back(j);

  for(int st=0;st<N;st++){
    vector<int> oddVis(N,0),evenVis(N,0);
    vector<int> onv,env;
    env.push_back(st);
    evenVis[st]=1;
    for(ll t=1;t<=min((ll)N,D);t++){
      if(t%2){
        for(auto now:env){
          for(auto nex:g[now]){
            if(oddVis[nex]) continue;
            oddVis[nex]=1;
            onv.push_back(nex);
          }
        }
        env.clear();
        if(onv.empty()) break;
      }else{
        for(auto now:onv){
          for(auto nex:g[now]){
            if(evenVis[nex]) continue;
            evenVis[nex]=1;
            env.push_back(nex);
          }
        }
        onv.clear();
        if(env.empty()) break;
      }
    }

    if(D%2){
      bool ng=false;
      rep(i,N) if(oddVis[i]==0) ng=true;
      if(ng){
        cout<<"No"<<endl;
        return 0;
      }
    }else{
      bool ng=false;
      rep(i,N) if(evenVis[i]==0) ng=true;
      if(ng){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }

  cout<<"Yes"<<endl;

  return 0;
}
0