Submission #75070183


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using PL = pair<ll,ll>;
template <class T>
using PQ = priority_queue<T>;
template <class T>
using PQG = priority_queue<T, vector<T>, greater<T>>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < (t); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (int)(a).size()
#define pb push_back
#define eb emplace_back
#define pob pop_back
template <class T>
bool chmax(T& a, const T& b) {return (a < b ? (a = b, true) : false);}
template <class T>
bool chmin(T& a, const T& b) {return (a > b ? (a = b, true) : false);}
const int INF = 2e9;
const ll LINF = 2e18;
const vector<int> di = {-1,1,0,0}, dj = {0,0,-1,1};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int t;
  cin >> t;
  rep(ti,t) {
    int n, a, b;
    cin >> n >> a >> b;
    a--; b--;
    vector visited(n,vector<bool>(n));
    string ans, path;
    auto dfs = [&](auto dfs, int i, int j) -> void {
      visited[i][j] = true;
      if(i == n-1 && j == n-1 && sz(path) == n*n-2) {
        ans = path;
        return;
      }
      rep(k,4) {
        int ni = i+di[k], nj = j+dj[k];
        if(ni < 0 || nj < 0 || ni >= n || nj >= n) continue;
        if(visited[ni][nj] || (ni == a && nj == b)) continue;
        path.pb("UDLR"[k]);
        dfs(dfs,ni,nj);
        path.pob();
      }
      visited[i][j] = false;
    };

    dfs(dfs,0,0);
    if(ans == "") cout << "No\n";
    else cout << "Yes\n" << ans << "\n";
  }
  return 0;
}

Submission Info

Submission Time
Task E - LRUD Moving
User WebP
Language C++23 (GCC 15.2.0)
Score 0
Code Size 1824 Byte
Status TLE
Exec Time > 2000 ms
Memory 207816 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 450
Status
AC × 1
AC × 1
TLE × 29
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 01_handmade_15.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3712 KiB
01_handmade_00.txt TLE > 2000 ms 207592 KiB
01_handmade_01.txt TLE > 2000 ms 207748 KiB
01_handmade_02.txt TLE > 2000 ms 207664 KiB
01_handmade_03.txt TLE > 2000 ms 207816 KiB
01_handmade_04.txt TLE > 2000 ms 207804 KiB
01_handmade_05.txt TLE > 2000 ms 207408 KiB
01_handmade_06.txt TLE > 2000 ms 106356 KiB
01_handmade_07.txt TLE > 2000 ms 207548 KiB
01_handmade_08.txt TLE > 2000 ms 4044 KiB
01_handmade_09.txt TLE > 2000 ms 207452 KiB
01_handmade_10.txt TLE > 2000 ms 3280 KiB
01_handmade_11.txt TLE > 2000 ms 3580 KiB
01_handmade_12.txt TLE > 2000 ms 9192 KiB
01_handmade_13.txt TLE > 2000 ms 8928 KiB
01_handmade_14.txt TLE > 2000 ms 8948 KiB
01_handmade_15.txt TLE > 2000 ms 8780 KiB
02_random_00.txt TLE > 2000 ms 183560 KiB
02_random_01.txt TLE > 2000 ms 207556 KiB
02_random_02.txt TLE > 2000 ms 207436 KiB
02_random_03.txt TLE > 2000 ms 37996 KiB
02_random_04.txt TLE > 2000 ms 207444 KiB
02_random_05.txt TLE > 2000 ms 3520 KiB
02_random_06.txt TLE > 2000 ms 11364 KiB
02_random_07.txt TLE > 2000 ms 171340 KiB
02_random_08.txt TLE > 2000 ms 30808 KiB
02_random_09.txt TLE > 2000 ms 53072 KiB
02_random_10.txt TLE > 2000 ms 93700 KiB
02_random_11.txt TLE > 2000 ms 41332 KiB
02_random_12.txt TLE > 2000 ms 85764 KiB