結果

問題 No.1400 すごろくで世界旅行
ユーザー 沙耶花沙耶花
提出日時 2021-02-19 22:23:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,720 bytes
コンパイル時間 2,396 ms
コンパイル使用メモリ 210,388 KB
実行使用メモリ 11,196 KB
最終ジャッジ日時 2023-10-15 02:51:07
合計ジャッジ時間 7,207 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 2 ms
4,500 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 3 ms
4,368 KB
testcase_07 AC 3 ms
4,372 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 2 ms
4,368 KB
testcase_12 AC 8 ms
4,368 KB
testcase_13 AC 89 ms
11,000 KB
testcase_14 AC 86 ms
11,028 KB
testcase_15 AC 78 ms
11,092 KB
testcase_16 AC 80 ms
11,196 KB
testcase_17 WA -
testcase_18 AC 76 ms
11,160 KB
testcase_19 AC 1 ms
4,372 KB
testcase_20 AC 2 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000



int main(){
	
	int V;
	cin>>V;
	
	long long D;
	cin>>D;
	
	vector<string> S(V);
	rep(i,V)cin>>S[i];
	
	vector<int> remain(V);
	rep(i,V){
		remain[i] = i;
	}
	mt19937 rnd(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
	auto start = chrono::system_clock::now();
	while(remain.size()>0){
		if(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count() > 2800){
			break;
		}
		
		int ind = rnd() % remain.size();
	//	cout<<remain[ind]<<endl;
		vector<int> d(V*2,Inf);
		d[remain[ind]*2] = 0;
		queue<int> Q;
		Q.push(remain[ind]*2);
		while(Q.size()>0){
			int u = Q.front()>>1;
			int b = Q.front()&1;
			Q.pop();
			rep(i,V){
				if(S[u][i]=='0')continue;
				int v = i;
				int nb = b^1;
				if(d[v*2+nb]!=Inf)continue;
				d[v*2+nb] = d[u*2+b]+1;
				Q.push(v*2+nb);
			}
		}
		vector<bool> ok(V,false);
		ok[remain[ind]] = true;
		bool f = true;
		rep(i,V){
			if(d[i*2+(D&1)]==Inf){
				f=false;
				break;
			}
			if(d[i*2+(D&1)]>D){
				f=false;
				break;
			}
		}
		if(!f)break;
		
		rep(i,V){
			bool F = true;
			rep(j,V){
				bool F2 = false;
				rep(k,2){
					int x = i*2 + k,y = j*2 + (k^(D&1));
					if(d[x]==Inf||d[y]==Inf)continue;
					if(d[x]+d[y]<=D){
						F2 = true;
						break;
					}
				}
				if(!F2){
					F=false;
					break;
				}
			}
			if(F)ok[i] = true;
		}
		vector<int> nr;
		rep(i,remain.size()){
			if(!ok[remain[i]])nr.push_back(remain[i]);
		}
		swap(remain,nr);
		
	}
	if(remain.size()==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
    return 0;
}
0