結果
問題 | No.1400 すごろくで世界旅行 |
ユーザー |
![]() |
提出日時 | 2021-02-19 23:05:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,489 ms / 3,153 ms |
コード長 | 2,589 bytes |
コンパイル時間 | 1,158 ms |
コンパイル使用メモリ | 101,068 KB |
最終ジャッジ日時 | 2025-01-19 01:30:27 |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#include <iostream>#include <algorithm>#include <iomanip>#include <vector>#include <queue>#include <set>#include <map>#include <bitset>#include <cassert>#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }using namespace std;typedef long long ll;using bits = bitset<2000>;// using bits = bitset<20>;struct matrix{int n, m;vector<bits> dat;matrix(int n_, int m_){n = n_; m = m_;for(int i = 0; i < n; i++){dat.push_back(bits());}}bits& operator[](int x) {return dat[x];}};bool prod(matrix a, matrix b, matrix &ans){assert(a.m == b.n);for(int i = 0; i < a.n; i++){ans[i] = bits();for(int j = 0; j < b.m; j++){if((a[i]&b[j]) != 0) {ans[i][j] = 1;}}}return true;}void copy_mat(matrix a, matrix &b){assert(a.n == b.n);assert(a.m == b.m);for(int i = 0; i < a.n; i++){for(int j = 0; j < a.m; j++){b.dat[i][j] = a.dat[i][j];}}}void pow_mat(matrix a, ll n, matrix &ans){assert(n < ((ll)1<<12));matrix buf(a.n, a.n);matrix tmp(a.n, a.n);copy_mat(a, tmp);for(int i = 0; i < a.n; i++) {for(int j = 0; j < a.n; j++){ans.dat[i][j] = 0;}ans.dat[i][i] = 1;}for(int i = 0; i <= 12; i++){ll m = (ll)1 << i;if(m&n){prod(tmp, ans, buf);copy_mat(buf, ans);}prod(tmp, tmp, buf);copy_mat(buf, tmp);}}int main(){ios::sync_with_stdio(false);cin.tie(0);cout << setprecision(10) << fixed;int v; ll d; cin >> v >> d;d = min((ll)2*v, d);matrix e(v, v), p(v, v);for(int i = 0; i < v; i++) cin >> e[i];// prod(e, e, p);pow_mat(e, d, p);// for(int i = 0; i < v; i++){// for(int j = 0; j < v; j++) cout << p[i][j];// cout << endl;// }// for(int i = 0; i < v; i++) cout << p[i] << endl;for(int i = 0; i < v; i++){for(int j = 0; j < v; j++){if(p[i][j] == 0) {cout << "No" << endl;return 0;}}}cout << "Yes" << endl;}