結果
| 問題 |
No.1400 すごろくで世界旅行
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2021-02-19 21:54:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,829 bytes |
| コンパイル時間 | 1,107 ms |
| コンパイル使用メモリ | 126,184 KB |
| 最終ジャッジ日時 | 2025-01-18 23:52:15 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 TLE * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:100:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
100 | scanf("%s", s);
| ~~~~~^~~~~~~~~
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template <int COL_SIZE> class mat {
private:
// (or, and) の意味での積(正方かつ対称行列に限る(重みなし無向グラフの隣接行列とか))
mat operator*(const mat& m) const {
mat ans;
for(int i = 0; i < COL_SIZE; i++){
for(int j = 0; j < COL_SIZE; j++){
if(this->a[i][j] == 0) continue;
ans.a[i] |= m.a[j];
}
}
return ans;
}
public:
bitset<COL_SIZE>* a;
int r;
// 正方行列の場合
mat() : mat(COL_SIZE){}
// 一般の行列の場合
mat(int row_size) : r(row_size){ a = new bitset<COL_SIZE>[r]; }
int rank() const {
int res = 0;
mat<COL_SIZE> b(r);
for(int i = 0; i < r; i++) b[i] = a[i];
for(int i = 0; i < COL_SIZE; i++){
if(res == r) return res;
int pivot = res;
if(!b[pivot][i]){
for(int j = res + 1; j < r; j++){
if(b[j][i]){
pivot = j;
break;
}
}
if(!b[pivot][i]) continue;
swap(b[pivot], b[res]);
}
for(int j = res + 1; j < r; j++){
if(b[j][i]) b[j] ^= b[res];
}
res++;
}
return res;
}
inline const bitset<COL_SIZE>& operator[](size_t index) const {
return a[index];
}
inline bitset<COL_SIZE>& operator[](size_t index){
return a[index];
}
friend mat pow(mat m, long long cnt){
mat res;
for(int i = 0; i < COL_SIZE; i++) res[i][i] = 1;
while(cnt){
if(cnt & 1){
res = res * m;
}
m = m * m;
cnt >>= 1;
}
return res;
}
};
int main()
{
int v; ll d;
cin>>v>>d;
mat<2000> e;
char s[2002];
for(int i=0; i<v; i++){
scanf("%s", s);
for(int j=0; j<v; j++){
e[i][j]=s[j]-'0';
}
}
auto f=pow(e, d);
for(int i=0; i<v; i++){
for(int j=0; j<v; j++){
if(!f[i][j]){
cout<<"No"<<endl;
return 0;
}
}
}
cout<<"Yes"<<endl;
return 0;
}
chocorusk