結果
| 問題 |
No.1400 すごろくで世界旅行
|
| コンテスト | |
| ユーザー |
N_N_Mochi
|
| 提出日時 | 2021-02-19 22:42:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,485 bytes |
| コンパイル時間 | 1,796 ms |
| コンパイル使用メモリ | 187,524 KB |
| 実行使用メモリ | 99,072 KB |
| 最終ジャッジ日時 | 2024-09-16 21:07:39 |
| 合計ジャッジ時間 | 7,178 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 RE * 6 |
ソースコード
//#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 = 1000;
vector<edge> G[MXV];
vector<vvl> d(MXV,vvl(MXV, vl(2,INF)));
void dijkstra(int i,int s){
priority_queue<pair<P,int>, vector<pair<P,int>>, greater<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.top();
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()){
edge e = G[V][k];
if(d[i][e.to][1^sig] > d[i][V][sig] + e.cost){
d[i][e.to][1^sig] = d[i][V][sig] + e.cost;
pair<P,int> neko;
neko.first=P(d[i][e.to][1^sig],e.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<vector<char>> A(V,vector<char>(V));
bool ok=true;
rep(i,V){
rep(j,V){
cin >> A[i][j];
if(A[i][j]=='0') ok=false;
}
}
rep(i,V){
rep(j,V){
if(A[i][j]=='1'){
edge e;
e.to=j;
e.cost=1;
G[i].push_back(e);
}
}
}
if(D==1&&(!ok)){
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;
}
N_N_Mochi