結果

問題 No.1400 すごろくで世界旅行
ユーザー leaf_1415leaf_1415
提出日時 2021-02-19 23:16:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,576 bytes
コンパイル時間 1,295 ms
コンパイル使用メモリ 112,152 KB
実行使用メモリ 46,696 KB
最終ジャッジ日時 2023-10-16 23:00:46
合計ジャッジ時間 6,684 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
6,004 KB
testcase_04 AC 2 ms
5,976 KB
testcase_05 AC 3 ms
5,976 KB
testcase_06 AC 10 ms
8,132 KB
testcase_07 AC 14 ms
8,192 KB
testcase_08 AC 3 ms
6,008 KB
testcase_09 AC 3 ms
6,000 KB
testcase_10 AC 5 ms
6,040 KB
testcase_11 AC 3 ms
5,992 KB
testcase_12 AC 62 ms
12,580 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size(); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define outl(x) cout << x << endl
#define SP << " " << 
#define inf 1e9

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<llint, llint> P;

ll n, d;
vector<int> G[4005];
int dist[4005][4005];

void bfs(vector<int> G[], int S, int dist[])
{
	queue<int> Q;
	Q.push(S);
	
	for(int i = 1; i <= 2*n; i++) dist[i] = inf;
	dist[S] = 0;
	
	while(Q.size()){
		int v = Q.front();
		Q.pop();
		for(int i = 0; i < G[v].size(); i++){
			if(dist[G[v][i]] < inf/2) continue;
			Q.push(G[v][i]);
			dist[G[v][i]] = dist[v] + 1;
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> d;
	char e;
	rep(i, 1, n) rep(j, 1, n){
		cin >> e;
		if(e == '1') G[i].push_back(n+j), G[n+i].push_back(j);
	}
	
	rep(i, 1, n) bfs(G, i, dist[i]);
	
	rep(i, 1, n) rep(j, 1, n){
		if(d % 2 == 0 && (ll)dist[i][j] > d){
			cout << "No" << endl;
			return 0;
		}
		if(d % 2 && (ll)dist[i][n+j] > d){
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	
	return 0;
}
0