QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#863822#9714. A Colorful GridIllusionaryDominanceAC ✓62ms13700kbC++205.6kb2025-01-19 23:08:122025-01-19 23:08:13

Judging History

你现在查看的是最新测评结果

  • [2025-01-19 23:08:13]
  • 评测
  • 测评结果:AC
  • 用时:62ms
  • 内存:13700kb
  • [2025-01-19 23:08:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
using ll = long long;

const int N = 1e5+5;
int f[N][2], last[N][2];
map<int, int> a[N];
int rig[N], lef[N];
bool con[N];

char trans(char x)
{
    if (x == 'D') return 'R';
    if (x == 'U') return 'L';
    if (x == 'R') return 'D';
    if (x == 'L') return 'U';
    return 'X';
}

bool sol(int n, int m, vector<pair<int,int>> X1, vector<pair<int,int>> X0, bool flx, bool tr)
{   
    // cerr << " ------------------ \n";
    vector<pair<int,int>> X[2] = {X0, X1};
    vector<pair<int,int>> fg;
    int nowr = 0;
    for (int i = 0; i < X[1].size(); ++i)
    {
        auto [l, r] = X[1][i];
        int j = i;
        nowr = X[1][i].second;
        while (j + 1 < X[1].size() && X[1][j + 1].first <= nowr) nowr = max(nowr, X[1][++j].second);
        fg.push_back({X[1][i].first, nowr});
        i = j;
    }
    
    if (fg.size() == 1 && fg[0].first == 1 && fg[0].second == m && flx) 
    {
        return 0;
    }
    for (int i = 0; i <= m; ++i) f[i][0] = f[i][1] = -1, con[i] = 0, a[i].clear(), last[i][0] = last[i][1] = -1, lef[i] = -3;
    f[0][0] = 0; f[0][1] = -1; f[1][0] = 0; f[1][1] = -1, last[1][0] = 0;
    
    for (auto [l, r] : X[0]) a[l][r] = 1, lef[r] = max(lef[r], l);
    for (auto [l, r] : fg) for (int j = l + 1; j <= r; ++j) con[j] = 1;
    
    // for (auto [l, r] : fg) cerr << l << "-" << r << " "; cerr << "\n";
    // for (auto [l, r] : X[0]) cerr << l << "|" << r << " "; cerr << "\n";
    
    bool notodd = n & 1;
    
    for (int i = 2; i <= m; ++i)
    {
        f[i][0] = f[i][1] = -1;
        // not put
        {
            if (f[i-1][1] != -1 && lef[i] < f[i-1][1])
            {
                f[i][1] = f[i-1][1];
                last[i][1] = 1;
            }
            // from f[i-1][0]
            else if (f[i-1][0] != -1 && lef[i] < f[i-1][0])
            {
                f[i][0] = f[i-1][0];
                last[i][0] = 0;
            }
        }
        // put
        if (!con[i])
        {
            int o = i & 1;
            if (f[i-2][o] != -1 && lef[i-1] < f[i-2][o] && lef[i-2] < f[i-2][o])
            {
                f[i][o] = i;
                last[i][o] = o;
            }
            if (f[i][o] != i && f[i-2][o^1] != -1 && !notodd && lef[i-1] < f[i-2][o^1] && lef[i-2] < f[i-2][o^1])
            {
                f[i][o] = i;
                last[i][o] = o ^ 1;
            }
        }
    }
    // cerr << f[7][1] << " " << last[7][1] << " " << f[5][1] << " " << f[4][0] << "\n";
    // cerr << f[0][0] << " " << f[0][1] << " " << f[1][0] << " " << f[1][1] << " " << f[2][0] << " " << f[2][1] << "\n";
    // return {0, vector<vector<char>>()};
    
    if (f[m][0] != -1 || f[m][1] != -1)
    {
        vector<vector<char>> ans(n+1, vector<char>(m+1, ' '));
        bool qiang = 0;
        for (int i = m, j = (f[m][1] != -1); i >= 1; ) 
        {
            if (f[i][j] == i)
            {
                // cerr << i << " " << j << "\n";
                for (int k = 1; k <= n; ++k) if (ans[k][i-1] == ' ') ans[k][i-1] = 'R', ans[k][i] = 'L';
                j = last[i][j]; i -= 2;
                qiang = 1;
            }
            else j = last[i][j], i -= 1;
        }
        if (!qiang)
        {
            if (n == 2 || m == 2) return 0;
            if (m % 2 == 0)
            {
                for (int i = 2; i <= m; i += 2)
                {
                    ans[1][i] = 'L'; ans[1][i-1] = 'R';
                    if (n % 2 == 0) ans[n][i] = 'L', ans[n][i-1] = 'R';
                }
                for (int i = 3; i <= m; i += 2)
                {
                    for (int j = 2; j <= n - (n % 2 == 0); ++j) ans[j][i] = 'L', ans[j][i-1] = 'R';
                }
                for (int i = 3; i <= n; i += 2) ans[i][1] = ans[i][m] = 'U', ans[i-1][1] = ans[i-1][m] = 'D';
            }
            else return 0;
        }
        for (int i = 2; i <= n; i += 2) for (int j = 1; j <= m; ++j) 
        if (ans[i][j] == ' ') ans[i][j] = 'U', ans[i-1][j] = 'D';
        for (int j = 1; j < m; ++j) if (ans[n][j] == ' ') ans[n][j] = 'R', ans[n][j+1] = 'L';
        cout << "Yes\n";
        if (tr)
        {
            for (int i = 1; i <= m; ++i, cout << "\n") for (int j = 1; j <= n; ++j) cout << trans(ans[j][i]);
        }
        else 
        {
            for (int i = 1; i <= n; ++i, cout << "\n") for (int j = 1; j <= m; ++j) cout << ans[i][j];
        }
        return 1;
    }
    return 0;
}

void solve()
{
    int n, m, k; cin >> n >> m >> k;
    vector<pair<int,int>> X[2], Y[2];
    bool flx = 0, fly = 0;
    for (int i = 1; i <= k; ++i) 
    {
        int x, y, v, w; cin >> x >> y >> v >> w;
        if (x > v) swap(x, v);
        if (y > w) swap(y, w);
        int o; cin >> o;
        if (o == 0 && x == v && y == w)
        {
            cout << "No\n";
            return ;
        }
        if (x != v) X[o].push_back({x, v});
        if (y != w) Y[o].push_back({y, w});
        if (x == v && y != w) flx = 1, X[o].push_back({x, v});
        if (y == w && x != v) fly = 1, Y[o].push_back({y, w});
    }
    sort(all(X[0])); sort(all(X[1])); sort(all(Y[0])); sort(all(Y[1]));
    if (sol(n, m, Y[1], Y[0], flx, 0)) return ;
    else if (sol(m, n, X[1], X[0], fly, 1)) return ;
    cout << "No\n";
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int T; cin >> T;
    for (int i = 1; i <= T; ++i) 
    {
        cout << "Case #" << i << ": ";
        solve();
    }
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 9796kb

input:

4
2 2 1
1 1 1 2 1
2 2 1
1 1 2 1 1
2 2 1
1 1 2 2 1
2 2 2
1 1 1 2 0
1 1 2 1 0

output:

Case #1: Yes
DD
UU
Case #2: Yes
RL
RL
Case #3: No
Case #4: No

result:

ok all accept

Test #2:

score: 0
Accepted
time: 3ms
memory: 8756kb

input:

4
2 10 7
1 1 2 1 1
1 9 1 10 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
1 6 2 8 0
2 10 6
1 1 2 1 1
1 8 1 10 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
2 10 6
1 1 2 2 0
1 8 2 10 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
2 10 7
1 1 2 2 0
1 9 2 10 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
1 6 2 8 0

output:

Case #1: Yes
DRLRLRLRLD
URLRLRLRLU
Case #2: Yes
DRLRLRLDDD
URLRLRLUUU
Case #3: Yes
RLRLRLRLDD
RLRLRLRLUU
Case #4: Yes
RLRLRLRLDD
RLRLRLRLUU

result:

ok all accept

Test #3:

score: 0
Accepted
time: 0ms
memory: 9760kb

input:

3
2 9 7
1 1 2 2 0
1 7 2 9 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
1 6 2 8 0
2 9 7
1 1 2 2 0
1 8 2 9 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
1 6 2 8 0
2 9 7
1 1 2 3 0
1 7 2 9 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
1 6 2 8 0

output:

Case #1: No
Case #2: Yes
RLRLRLRLD
RLRLRLRLU
Case #3: Yes
DRLRLRLDD
URLRLRLUU

result:

ok all accept

Test #4:

score: 0
Accepted
time: 1ms
memory: 8692kb

input:

4
2 9 1
1 1 2 9 1
2 10 1
1 1 2 10 1
3 4 1
1 1 3 4 1
4 4 1
1 1 4 4 1

output:

Case #1: No
Case #2: No
Case #3: Yes
RLRL
DRLD
URLU
Case #4: Yes
RLRL
DRLD
URLU
RLRL

result:

ok all accept

Test #5:

score: 0
Accepted
time: 1ms
memory: 8260kb

input:

4
2 10 5
1 1 2 3 1
1 7 2 10 1
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
2 10 6
1 1 2 3 1
1 7 2 10 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
2 10 7
1 1 2 3 1
1 7 2 10 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
1 6 2 8 0
2 10 7
1 1 2 2 1
1 7 2 10 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
1 2 2 3 0

output:

Case #1: Yes
DDDRLRLDDD
UUURLRLUUU
Case #2: Yes
DDRLRLDDDD
UURLRLUUUU
Case #3: No
Case #4: Yes
DRLRLRLDDD
URLRLRLUUU

result:

ok all accept

Test #6:

score: 0
Accepted
time: 1ms
memory: 8504kb

input:

2
4 4 1
2 2 3 3 0
4 4 2
2 2 3 3 0
3 3 4 1 0

output:

Case #1: Yes
DRLD
URLU
DRLD
URLU
Case #2: Yes
DRLD
URLU
DRLD
URLU

result:

ok all accept

Test #7:

score: 0
Accepted
time: 2ms
memory: 8436kb

input:

1
2 12 6
1 1 2 2 1
1 3 2 5 0
1 6 2 8 0
1 7 2 9 0
1 9 2 11 0
1 11 2 12 0

output:

Case #1: Yes
DDRLRLRLRLRL
UURLRLRLRLRL

result:

ok all accept

Test #8:

score: 0
Accepted
time: 1ms
memory: 8784kb

input:

1
4 3 2
1 1 4 3 0
1 1 2 3 1

output:

Case #1: Yes
RLD
RLU
DDD
UUU

result:

ok all accept

Test #9:

score: 0
Accepted
time: 54ms
memory: 13700kb

input:

2
20000 4 100000
1 1 1 4 1
4 3 13 2 0
4 3 6 4 1
2 1 6 2 0
1 3 10 3 0
4 4 13 3 0
1 4 5 4 0
2 4 10 4 0
3 4 7 1 0
2 4 12 3 0
1 2 9 2 0
4 2 9 1 1
4 1 7 4 1
1 3 11 3 0
1 1 4 4 0
3 3 9 2 0
2 3 9 4 0
3 4 4 2 0
2 4 6 1 0
1 3 2 1 1
3 2 4 2 0
2 1 7 4 0
2 4 7 2 0
4 2 8 4 1
3 1 6 1 0
3 4 9 2 0
1 1 7 1 0
1 3 9 3...

output:

Case #1: Yes
RLRL
RLRL
DDDD
UUUU
RLRL
RLRL
RLRL
RLRL
RLRL
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DDDD
UUUU
DD...

result:

ok all accept

Test #10:

score: 0
Accepted
time: 45ms
memory: 12292kb

input:

2
6 15000 100000
1 1 6 1 1
3 2 1 8 0
1 4 5 5 1
3 3 3 12 0
6 2 3 8 0
1 3 5 5 1
4 2 4 3 1
6 2 1 7 0
6 3 6 5 1
4 1 6 7 0
5 2 3 4 1
1 4 4 11 0
2 6 1 16 0
2 5 6 7 0
6 2 5 12 0
5 4 3 6 0
2 1 2 9 0
6 5 3 10 0
3 1 3 4 1
2 6 5 15 0
6 6 5 9 1
3 5 2 15 0
6 1 6 6 0
6 4 2 6 0
6 6 4 8 1
2 5 6 10 0
5 2 4 11 0
2 5 ...

output:

Case #1: Yes
DDDDRLDDDRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL...

result:

ok all accept

Test #11:

score: 0
Accepted
time: 49ms
memory: 12892kb

input:

2
10000 10 100000
1 1 1 10 1
4 1 11 3 0
7 4 12 3 0
7 2 11 6 0
4 7 5 1 1
9 9 14 10 0
10 3 12 6 0
1 5 3 8 1
4 4 7 8 1
8 2 10 10 1
4 7 12 4 0
9 4 11 3 0
4 2 10 9 1
5 3 15 9 0
10 1 16 7 0
5 9 10 7 1
8 7 15 10 0
5 2 9 8 1
9 10 10 2 1
7 6 10 3 1
9 6 12 4 0
1 4 3 1 1
4 10 9 3 1
4 5 14 9 0
1 8 9 1 1
4 3 10 ...

output:

Case #1: Yes
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
DDDDDDDDDD
UUUUUUUUUU
DDDDDDDDDD
UUUUUUUUUU
DDDDDDDDDD
UUUUUUUUUU
DDDDDDDDDD
UUUUUUUUUU
DDDDDDDDDD
UUUUUUUUUU
DDDDDDDDDD
UUUUUUUUUU
DDDDDDDDDD
UUUUUUUUUU
DDDDDDDDDD
UUUUUUUUUU
DDDDDDDDDD
U...

result:

ok all accept

Test #12:

score: 0
Accepted
time: 50ms
memory: 13456kb

input:

2
5 20000 100000
1 1 5 1 1
4 5 5 8 1
3 1 1 3 1
4 2 4 12 1
3 5 2 11 1
1 2 5 5 1
1 4 2 12 1
3 4 5 6 1
3 2 5 8 1
2 5 4 7 1
3 5 1 8 1
3 1 5 5 1
3 4 2 12 1
1 3 1 13 1
1 4 2 6 1
3 4 3 6 1
1 5 1 6 1
4 5 2 15 0
2 4 1 7 1
2 1 4 10 1
5 4 1 9 1
5 5 4 11 1
2 1 3 11 1
3 5 2 9 1
4 5 1 12 1
1 5 4 7 1
1 2 5 4 1
5 5...

output:

Case #1: Yes
DDDDDDDDDDDDRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR...

result:

ok all accept

Test #13:

score: 0
Accepted
time: 53ms
memory: 13096kb

input:

2
5 19998 100000
1 1 5 1 1
1 3 3 9 0
4 4 2 8 1
3 1 4 9 0
5 1 1 9 0
1 1 5 8 0
2 3 2 6 0
5 5 1 15 0
4 5 4 14 0
3 4 4 12 0
3 5 1 10 0
3 2 2 12 0
1 5 3 8 1
3 2 3 6 0
4 1 1 9 0
5 1 4 5 0
5 1 5 4 0
1 2 2 12 0
4 4 3 8 1
5 2 2 4 0
2 5 5 10 0
4 3 1 4 0
3 2 1 12 0
4 1 2 10 0
3 5 2 6 1
4 3 3 9 0
3 4 5 11 0
1 5...

output:

Case #1: Yes
RLRLDDDDRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR...

result:

ok all accept

Test #14:

score: 0
Accepted
time: 53ms
memory: 12972kb

input:

2
12000 7 100000
1 1 1 7 1
3 2 9 4 0
7 2 9 5 1
2 1 10 1 0
3 6 8 7 0
3 5 12 7 0
1 3 11 2 0
6 1 8 4 1
7 2 11 7 0
6 5 13 2 0
7 2 15 3 0
1 6 5 2 1
5 7 15 7 0
3 4 13 3 0
7 6 11 1 0
6 2 16 1 0
5 4 6 2 0
3 5 11 2 0
1 2 9 1 0
7 2 15 1 0
1 1 9 5 0
6 4 15 6 0
7 3 16 4 0
4 1 5 4 1
7 5 12 2 0
7 5 13 4 0
5 5 14 ...

output:

Case #1: Yes
RLRLRLD
RLRLRLU
RLRLRLD
RLRLRLU
DDDDDDD
UUUUUUU
RLRLRLD
RLRLRLU
DDDDDDD
UUUUUUU
DDDDDDD
UUUUUUU
DDDDDDD
UUUUUUU
DDDDDDD
UUUUUUU
DDDDDDD
UUUUUUU
DDDDDDD
UUUUUUU
DDDDDDD
UUUUUUU
DDDDDDD
UUUUUUU
DDDDDDD
UUUUUUU
DDDDDDD
UUUUUUU
DDDDDDD
UUUUUUU
DDDDDDD
UUUUUUU
DDDDDDD
UUUUUUU
DDDDDDD
UUUUUUU...

result:

ok all accept

Test #15:

score: 0
Accepted
time: 62ms
memory: 12036kb

input:

2
15 6000 100000
1 1 15 1 1
10 4 5 8 0
12 14 15 15 1
5 10 15 14 0
5 6 8 14 0
12 10 1 13 0
9 8 8 9 1
3 1 8 8 0
13 8 3 13 0
15 15 5 19 0
3 2 11 7 0
9 2 6 4 1
5 6 3 13 0
2 9 9 10 0
2 13 11 16 0
1 9 7 12 0
15 10 2 16 0
9 15 2 17 0
8 14 1 21 0
3 8 2 18 0
8 5 11 12 0
11 13 9 18 0
14 12 11 15 0
9 3 8 7 0
8...

output:

Case #1: Yes
DDDDRLDDRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR...

result:

ok all accept

Test #16:

score: 0
Accepted
time: 0ms
memory: 9932kb

input:

10
4 9 20
1 1 4 1 1
1 2 4 5 0
3 3 4 8 0
3 2 2 9 0
3 1 4 9 0
3 2 2 9 0
3 2 1 6 0
2 3 1 9 0
4 3 3 9 0
4 3 4 6 0
3 1 3 7 0
3 2 3 9 0
1 1 3 9 0
4 2 4 6 0
3 3 2 9 0
3 2 3 9 0
2 1 3 7 0
2 1 3 7 0
4 4 2 9 0
1 4 3 9 0
9 4 20
1 1 1 4 1
1 3 9 2 0
1 1 9 1 0
3 4 9 1 0
1 2 9 2 0
3 2 4 4 1
1 2 6 2 1
1 1 7 3 0
2 2...

output:

Case #1: Yes
DRLRLRLRL
URLRLRLRL
DRLRLRLRL
URLRLRLRL
Case #2: Yes
RLRL
RLRL
RLRL
RLRL
RLRL
DDDD
UUUU
DDDD
UUUU
Case #3: Yes
DDDDDRLRL
UUUUURLRL
DDDDDRLRL
UUUUURLRL
Case #4: Yes
RLRL
DDDD
UUUU
RLRL
RLRL
RLRL
DDDD
UUUU
RLRL
Case #5: Yes
RLRL
DDDD
UUUU
RLRL
RLRL
RLRL
RLRL
DDDD
UUUU
Case #6: Yes
RLRL
DD...

result:

ok all accept

Test #17:

score: 0
Accepted
time: 0ms
memory: 8444kb

input:

10
5 10 20
1 1 5 1 1
1 1 1 9 0
4 2 1 4 1
3 3 1 6 0
4 5 1 6 0
2 5 2 7 0
4 4 5 9 0
1 3 4 8 0
2 5 2 8 0
2 1 4 2 1
2 3 2 10 0
1 1 4 2 1
1 2 1 6 0
2 2 3 7 0
2 3 2 10 0
1 3 3 10 0
4 1 3 6 0
1 2 3 6 0
2 4 1 10 0
2 1 2 8 0
10 5 20
1 1 1 5 1
4 5 10 4 0
3 4 4 3 1
1 3 6 2 0
4 2 5 1 1
2 1 10 3 0
1 1 5 3 1
2 3 4...

output:

Case #1: Yes
DDDDRLRLRL
UUUURLRLRL
DDDDRLRLRL
UUUURLRLRL
RLRLRLRLRL
Case #2: Yes
RLRLD
RLRLU
RLRLD
RLRLU
DDDDD
UUUUU
DDDDD
UUUUU
DDDDD
UUUUU
Case #3: No
Case #4: Yes
DDRLRLRLRL
UURLRLRLRL
DDRLRLRLRL
UURLRLRLRL
RLRLRLRLRL
Case #5: Yes
DDRLDDDDRL
UURLUUUURL
DDRLDDDDRL
UURLUUUURL
RLRLRLRLRL
Case #6: Ye...

result:

ok all accept

Test #18:

score: 0
Accepted
time: 1ms
memory: 8396kb

input:

100
3 4 5
1 1 3 1 1
3 2 3 4 1
2 3 1 4 1
1 1 3 4 0
3 1 2 4 0
3 4 5
1 1 3 1 1
3 3 1 4 0
2 3 1 4 0
1 2 2 4 0
1 3 1 4 0
4 3 5
1 1 1 3 1
1 1 4 1 0
3 2 4 2 0
1 2 4 1 0
3 2 4 2 0
3 4 5
1 1 3 1 1
1 3 2 4 0
2 3 1 4 0
2 3 1 4 0
2 1 1 3 1
3 4 5
1 1 3 1 1
2 2 1 4 1
2 1 1 4 0
1 1 2 4 0
3 1 2 2 0
4 3 5
1 1 1 3 1
...

output:

Case #1: Yes
RLDD
RLUU
RLRL
Case #2: Yes
RLRL
RLRL
RLRL
Case #3: Yes
DDD
UUU
DDD
UUU
Case #4: Yes
DDRL
UURL
RLRL
Case #5: Yes
RLDD
RLUU
RLRL
Case #6: Yes
RLD
RLU
DDD
UUU
Case #7: Yes
DDD
UUU
RLD
RLU
Case #8: Yes
RLRL
RLRL
RLRL
Case #9: Yes
RLRL
RLRL
RLRL
Case #10: Yes
DDD
UUU
RLD
RLU
Case #11: Yes
D...

result:

ok all accept

Extra Test:

score: 0
Extra Test Passed