Submission

Status:
Compilation Error

Score: 0

User: tull

Problemset: Sirabyrinth 1

Language: cpp

Time: 0.000 second

Submitted On: 2025-04-12 17:40:44

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define ll long long
template <class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <class T> using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
using pil=pair<int,long long>;
using pli=pair<long long,int>;
using pll=pair<long long,long long>;
using pii=pair<int,int>;
using piii=pair<pair<int,int>,int>;
using plll=pair<pair<ll,ll>,ll>;
using pic=pair<int,char>;
const int MX= 1000000000000000000LL; //1e18
const int MN=-MX; //-1e18
const int MOD = 1e9+7;
#define bp '\n'
#define ull unsigned long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define inv(a) for(auto&e:a){cin>>e;}
#define vp cout<<'\n';
#define inv2dm(a) for(auto&e:a)for(auto&c:e)cin>>c;
#define ck(a) for(auto&e:a)cout<<e<<' ';cout<<'\n';
#define ckpf(a) for(auto&e:a)printf("%d ",e);printf("\n");
#define ckpair(a) for(auto&[f,s]:a)cout<<"("<<f<<", "<<s<<") ";cout<<'\n';
#define LMX LLONG_MAX
#define LMN LLONG_MIN
#define ck2dm(a) cout<<'\n';for(auto&e:a){for(auto&c:e)cout<<((c==MX or c==MN)?9:c)<<' ';cout<<'\n';}
#define ck2dmlr(a,l,r) cout<<'\n';for(int i=0;i<l;++i){for(int j=0;j<r;++j){cout<<((a[i][j]==MN or a[i][j]==MX)?9:a[i][j])<<'\t';}cout<<'\n';}
#define tostr(a) to_string(a)
#define qs(a) for(int i=1;i<a.size();++i)a[i]+=a[i-1];
#define vpii vector<pair<int,int>>
#define dir vector<pair<int,int>>direct={{-1,0},{1,0},{0,1},{0,-1}};
#define val(i,j) (i>=0 and i<n and j>=0 and j<m)?1:0
#define vi vector<int>
#define mt make_tuple
#define mp make_pair
#define db double
int n,m;
vector<string>a(101);
bool visit[101][101];
bool fnd=false;
void dfs(int i,int j,string k){
    if(!val(i,j) or fnd)
        return;
    if(a[i][j]=='#' or visit[i][j])
        return;
    //cout<<cnt++<<" : "<<i<<' '<<j<<bp;
    if(i==0 or j==0 or i==n-1 or j==m-1){
        cout<<k.size()<<bp<<k;
        fnd=true;
        return;
    }
    visit[i][j]=true;
    dfs(i-1,j,k+'U');
    dfs(i+1,j,k+'D');
    dfs(i,j-1,k+'L');
    dfs(i,j+1,k+'R');
    return;
}
signed main(){
    //freopen("test_input.txt","r",stdin);
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    int si,sj;
    for(int i=0;i<n;++i){
        cin>>a[i];
        for(int j=0;j<m;++j){
            if(a[i][j]=='S'){
                si=i,sj=j;
            }
        }
    }
    dfs(si,sj,"");
    return 0;
}