社区讨论
求条qwq
CF1749ECactus Wall参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mjv21fp5
- 此快照首次捕获于
- 2026/01/01 14:19 2 个月前
- 此快照最后确认于
- 2026/01/03 19:10 2 个月前
wrong answer the jury's answer is better than the participant's answer (test case 563).jpgcode
CPP// Code By: zyx
// 11:24 12:09 13:00
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define caofeini chutiren
const int dx[] = {1, -1};
const int dy[] = {1, 1};
void please_ac(){
int n, m; cin >> n >> m;
vector <vector <int>> mp(n + 2, vector <int> (m + 2, 1));
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= m; j ++ ){
char c; cin >> c;
if (c == '#') mp[i][j] = 0;
else mp[i][j] = 1;
}
deque <pair<int, int>> q;
vector <vector <int>> stp(n + 2, vector <int> (m + 2, 0x3f3f3f3f));
for (int i = 1; i <= n; i ++ )
if (!mp[i][1]){
q.push_back({i, 1});
stp[i][1] = 0;
}
for (int i = 1; i <= n; i ++ )
if (mp[i][1]){
if (!mp[i - 1][1] || !mp[i + 1][1] || !mp[i][2]) continue;
q.push_back({i, 1});
stp[i][1] = 1;
}
vector <vector <pair<int, int>>> pre(n + 2, vector <pair<int, int>> (m + 2));
while (q.size()){
auto t = q.front(); q.pop_front();
int x = t.fi, y = t.se;
for (int u = 0; u < 2; u ++ ){
int nx = x + dx[u];
int ny = y + dy[u];
if (nx < 1 || nx > n || ny < 1 || ny > m) continue;
if (!mp[nx - 1][ny] || !mp[nx][ny - 1] || !mp[nx + 1][ny] || !mp[nx][ny + 1]) continue;
if (stp[nx][ny] < stp[x][y] + mp[nx][ny]) continue;
stp[nx][ny] = stp[x][y] + mp[nx][ny];
if (!mp[nx][ny]) q.push_front({nx, ny});
else q.push_back({nx, ny});
pre[nx][ny] = {x, y};
}
}
int x = 0;
for (int i = 1; i <= n; i ++ ) if (stp[x][m] > stp[i][m]) x = i;
if (stp[x][m] == 0x3f3f3f3f) cout << "NO\n";
else{
pair<int, int> now = {x, m};
while (now.se != 1){
mp[now.fi][now.se] = 0;
now = pre[now.fi][now.se];
}
mp[now.fi][now.se] = 0;
cout << "YES\n";
for (int i = 1; i <= n; i ++ ){
for (int j = 1; j <= m; j ++ ) cout << (mp[i][j] ? '.' : '#');
cout << "\n";
}
return ;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T_T = 1;
cin >> T_T;
while (T_T -- ) please_ac();
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...