結果
| 問題 |
No.2641 draw X
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-10 20:55:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 669 ms / 2,000 ms |
| コード長 | 2,232 bytes |
| コンパイル時間 | 2,199 ms |
| コンパイル使用メモリ | 205,748 KB |
| 最終ジャッジ日時 | 2025-02-20 03:45:08 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> istream& operator >> (istream& is, vector<T>& vec) {
for(T& x : vec) is >> x;
return is;
}
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
if(vec.empty()) return os;
os << vec[0];
for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
return os;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int h, w;
cin >> h >> w;
vector<string> A(h);
cin >> A;
vector dp(h, vector(w, vector<int>(4, -1)));
vector dp2(h, vector(w, vector<int>(4)));
auto rec = [&](auto rec, int y, int x, int ds) -> int {
if(y < 0 || x < 0 || y >= h || x >= w) return 0;
if(dp[y][x][ds] != -1) return dp[y][x][ds];
if(A[y][x] == '.') return dp[y][x][ds] = 0;
return dp[y][x][ds] = 1 + rec(rec, y + (ds & 1 ? 1 : -1), x + (ds & 2 ? 1 : -1), ds);
};
for(int y = 0; y < h; y++){
for(int x = 0; x < w; x++){
if(A[y][x] == '.') continue;
int ans = 1 << 30;
for(int s = 0; s < 4; s++){
ans = min(ans, rec(rec, y, x, s));
}
if(ans >= 2) fill(dp2[y][x].begin(), dp2[y][x].end(), ans);
}
}
for(int s = 0; s < 4; s++){
int dx = s & 2 ? 1 : -1;
if(s & 1){
for(int y = 0; y + 1 < h; y++){
for(int x = 0; x < w; x++){
if(x + dx < 0 || x + dx >= w) continue;
dp2[y + 1][x + dx][s] = max(dp2[y + 1][x + dx][s], dp2[y][x][s] - 1);
}
}
}else{
for(int y = h - 1; y >= 1; y--){
for(int x = 0; x < w; x++){
if(x + dx < 0 || x + dx >= w) continue;
dp2[y - 1][x + dx][s] = max(dp2[y - 1][x + dx][s], dp2[y][x][s] - 1);
}
}
}
}
for(int y = 0; y < h; y++){
for(int x = 0; x < w; x++){
if(A[y][x] == '.') continue;
if(accumulate(dp2[y][x].begin(), dp2[y][x].end(), 0) == 0){
cout << "No\n";
return 0;
}
}
}
cout << "Yes\n";
}