提出 #75445334
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template<class T> inline bool chmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
const int MOD = 1e9 + 7;
void solve() {
int n,m;cin>>n>>m;
vector<vector<int>> adj(n);
for(int i=0;i<n;i++)adj[i].push_back(i);
for(int i=0;i<m;i++){
int u,v;cin>>u>>v;
u--;v--;
adj[u].pb(v);
adj[v].pb(u);
}
int w;cin>>w;
vector<string> s(n);
for(int i=0;i<n;i++)cin>>s[i];
vector<int> vis(n*w,0);
auto dfs=[&](auto&& self,int u,int d)->bool{
int state=u*w+d;
if(vis[state]==1)return true;
if(vis[state]==2)return false;
vis[state]=1;
int idx=(d+1)%w;
for(int v:adj[u]){
if(s[v][idx]=='o'){
if(self(self,v,idx))return true;
}
}
vis[state]=2;
return false;
};
for(int i=0;i<n;i++){
if(s[i][0]=='o'&&vis[i*w]==0){
if(dfs(dfs,i,0)){
cout<<"Yes\n";
return;
}
}
}
cout<<"No\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt = 1;
cin>>tt;
while (tt--) {
solve();
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | E - Endless Holidays |
| ユーザ | lavi3 |
| 言語 | C++23 (GCC 15.2.0) |
| 得点 | 450 |
| コード長 | 1585 Byte |
| 結果 | AC |
| 実行時間 | 54 ms |
| メモリ | 28452 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 450 / 450 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_01.txt |
| All | 00_sample_01.txt, 01_small_random_01.txt, 01_small_random_02.txt, 01_small_random_03.txt, 01_small_random_04.txt, 02_medium_random_01.txt, 02_medium_random_02.txt, 02_medium_random_03.txt, 02_medium_random_04.txt, 03_large_sparse_01.txt, 03_large_sparse_02.txt, 03_large_sparse_03.txt, 03_large_sparse_04.txt, 04_long_01.txt, 04_long_02.txt, 04_long_03.txt, 04_long_04.txt, 05_hand_01.txt, 05_hand_02.txt, 05_hand_03.txt, 05_hand_04.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_01.txt | AC | 2 ms | 3512 KiB |
| 01_small_random_01.txt | AC | 16 ms | 3648 KiB |
| 01_small_random_02.txt | AC | 17 ms | 3636 KiB |
| 01_small_random_03.txt | AC | 17 ms | 3728 KiB |
| 01_small_random_04.txt | AC | 17 ms | 3672 KiB |
| 02_medium_random_01.txt | AC | 18 ms | 4540 KiB |
| 02_medium_random_02.txt | AC | 17 ms | 4696 KiB |
| 02_medium_random_03.txt | AC | 17 ms | 4636 KiB |
| 02_medium_random_04.txt | AC | 17 ms | 4656 KiB |
| 03_large_sparse_01.txt | AC | 19 ms | 5908 KiB |
| 03_large_sparse_02.txt | AC | 19 ms | 5992 KiB |
| 03_large_sparse_03.txt | AC | 19 ms | 5252 KiB |
| 03_large_sparse_04.txt | AC | 21 ms | 5948 KiB |
| 04_long_01.txt | AC | 26 ms | 7444 KiB |
| 04_long_02.txt | AC | 25 ms | 7552 KiB |
| 04_long_03.txt | AC | 25 ms | 7184 KiB |
| 04_long_04.txt | AC | 25 ms | 7456 KiB |
| 05_hand_01.txt | AC | 52 ms | 22100 KiB |
| 05_hand_02.txt | AC | 54 ms | 28452 KiB |
| 05_hand_03.txt | AC | 27 ms | 16200 KiB |
| 05_hand_04.txt | AC | 22 ms | 3568 KiB |