結果
| 問題 |
No.2411 Reverse Directions
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2023-08-11 22:54:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 4,251 bytes |
| コンパイル時間 | 1,709 ms |
| コンパイル使用メモリ | 137,828 KB |
| 最終ジャッジ日時 | 2025-02-16 01:56:57 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 RE * 1 |
| other | AC * 14 WA * 3 RE * 12 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#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;
template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
return vector<vector<T>>(n, vector<T>(m, v));
}
template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}
template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
if(v.empty()) {
cout << endl;
return;
}
for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
cout << v.back() << endl;
}
using P = pair<int, int>;
using T = tuple<int, int, int>;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
int h, w, k, l, r; cin >> h >> w >> k >> l >> r; l--;
vector<string> s(h);
for(int i = 0; i < h; i++) cin >> s[i];
auto fx = [&](int i, int j){
if(i-1 >= 0 && i+1 < h){
if(s[i-1][j] == '.' && s[i][j] == '.' && s[i+1][j] == '.') return true;
}
return false;
};
auto fy = [&](int i, int j){
if(j-1 >= 0 && j+1 < w){
if(s[i][j-1] == '.' && s[i][j] == '.' && s[i][j+1] == '.') return true;
}
return false;
};
auto f = [&](int i, int j){
return fx(i, j) || fy(i, j);
};
if(r%2 != l%2){
cout << "No" << endl;
return 0;
}
if((h+w-2)%2 != (k-(r-l))%2){
cout << "No" << endl;
return 0;
}
if((h+w-2) > k-(r-l)){
cout << "No" << endl;
return 0;
}
int extra = k-(h-1)-(w-1);
auto pre = vec3d(h, w, 2, T(-1, -1, -1));
auto ok = vec3d(h, w, 2, false);
ok[0][0][0] = true;
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
for(int k = 0; k < 2; k++){
if(!ok[i][j][k]) continue;
if(i+1 < h && s[i+1][j] == '.'){
int kk = k;
if(f(i+1, j) && i+j+1 <= l && (i+j+1)%2 == l%2 && i+j+1+extra >= r) kk = 1;
ok[i+1][j][kk] = true;
pre[i+1][j][kk] = {i, j, k};
}
if(j+1 < w){
int kk = k;
if(f(i, j+1) && i+j+1 <= l && (i+j+1)%2 == l%2 && i+j+1+extra >= r) kk = 1;
ok[i][j+1][kk] = true;
pre[i][j+1][kk] = {i, j, k};
}
}
}
}
if(!ok[h-1][w-1][1]){
cout << "No" << endl;
return 0;
}
int x = h-1, y = w-1, p = 1;
if(!ok[h-1][w-1][1]) p = 0;
vector<P> path = {P(x, y)};
while(true){
auto [xx, yy, pp] = pre[x][y][p];
x = xx;
y = yy;
p = pp;
path.push_back({x, y});
if(x == 0 && y == 0) break;
}
reverse(path.begin(), path.end());
int len = path.size();
string ans;
for(int i = 0; i < len-1; i++){
auto [x, y] = path[i];
auto [xx, yy] = path[i+1];
if(xx == x+1){
ans += 'D';
}
if(yy == y+1){
ans += 'R';
}
if(extra == 0) continue;
if(f(xx, yy) && ans.size() <= l && ans.size()%2 == l%2 && ans.size()+extra >= r) {
if(fx(xx, yy)){
while(extra){
ans += "UD";
extra -= 2;
}
}else{
assert(fy(xx, yy));
while(extra){
ans += "LR";
extra -= 2;
}
}
}
}
cout << ans << endl;
return 1;
}
milanis48663220