General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
173800006 Practice:
arnab_baishnab
359E - 33 C++20 (GCC 11-64) Accepted 62 ms 34936 KB 2022-09-28 13:29:05 2022-09-28 13:29:05
→ Source
#include<bits/stdc++.h>
using namespace std;
#define   MP             make_pair
#define   PB             push_back
#define   nn             '\n'
#define   endl           '\n'
#define   IOS            ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define   UNIQUE(vec)    vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end()))) ;
#define   all(vec)       vec.begin(),vec.end()
#define   int            long long
#define   pii            pair<int,int>
#define   pdd            pair<double,double>

typedef long long LL ;

const int MOD=1e9+7,Base=998244353 ;
const int N=1e6+7 ;
const int oo=1LL*1000*1000*1000*1000*1000*1000+7LL, INF2=(1LL<<62) ;
const double pie=acos(-1.0) ;
const double EPS=1e-9 ;
const int maxn=1e5+7 ;

int n , xo , yo , dx[]={-1,+1,0,0} , dy[]={0,0,-1,+1} ;

int a[507][507] , vis[507][507] ;

string cmd="" , m="UDLR" ;

bool in(int x,int y)
{
    return x>=1 and x<=n and y>=1 and y<=n ;
}

void dfs(int x,int y,char mv)
{
     if(a[x][y]==0)
        cmd.push_back('1') , a[x][y]^=1 ;

     vis[x][y]=1 ;

     for(int i=0;i<4;++i)
     {
         for(int k=1;k<=n;++k)
         {
             if(vis[x+dx[i]*k][y+dy[i]*k])
                break ;
             if(in(x+dx[i]*k,y+dy[i]*k) and vis[x+dx[i]*k][y+dy[i]*k]==0 and a[x+dx[i]*k][y+dy[i]*k])
             {
                 cmd.push_back(m[i]) ;
                 dfs(x+dx[i],y+dy[i],m[i]) ;
                 break ;
             }
         }
     }

     if(a[x][y]==1)
        cmd.push_back('2') , a[x][y]^=1 ;

     if(mv=='L')
        cmd.push_back('R') ;

     if(mv=='R')
        cmd.push_back('L') ;

     if(mv=='U')
        cmd.push_back('D') ;

     if(mv=='D')
        cmd.push_back('U') ;
}

int32_t main()
{
    IOS

    cin>>n>>xo>>yo ;

    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n;++j)
        {
            cin>>a[i][j] ;
        }
    }

    dfs(xo,yo,'#') ;

    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n;++j)
        {
            if(a[i][j]==1)
                cout<<"NO\n" , exit(0) ;
        }
    }

    cout<<"YES\n"<<cmd<<endl ;

    return 0 ;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details