QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725154#9714. A Colorful GridzltAC ✓43ms33620kbC++146.3kb2024-11-08 16:28:542024-11-08 16:28:54

Judging History

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

  • [2024-11-08 16:28:54]
  • 评测
  • 测评结果:AC
  • 用时:43ms
  • 内存:33620kb
  • [2024-11-08 16:28:54]
  • 提交

answer

#include <bits/stdc++.h>
#define ID(x, y) (((x) - 1) * m + (y))
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;

const int maxn = 400100;

int n, m, K;
bool flag;
char ans[maxn];

struct node {
	int x1, y1, x2, y2, x;
} a[maxn];

inline void print() {
	puts("Yes");
	if (flag) {
		for (int i = 1; i <= m; ++i) {
			for (int j = 1; j <= n; ++j) {
				char c = ans[ID(j, i)];
				if (c == 'D') {
					c = 'R';
				} else if (c == 'U') {
					c = 'L';
				} else if (c == 'R') {
					c = 'D';
				} else {
					c = 'U';
				}
				putchar(c);
			}
			putchar('\n');
		}
	} else {
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				putchar(ans[ID(i, j)]);
			}
			putchar('\n');
		}
	}
}

namespace Sub1 {
	int fa[maxn];
	
	int find(int x) {
		return fa[x] == x ? x : fa[x] = find(fa[x]);
	}
	
	void solve() {
		if (n & 1) {
			flag ^= 1;
			swap(n, m);
			for (int i = 1; i <= K; ++i) {
				swap(a[i].x1, a[i].y1);
				swap(a[i].x2, a[i].y2);
			}
		}
		if (n % 2 == 0 && m % 2 == 0 && n > m) {
			flag ^= 1;
			swap(n, m);
			for (int i = 1; i <= K; ++i) {
				swap(a[i].x1, a[i].y1);
				swap(a[i].x2, a[i].y2);
			}
		}
		bool fl = 1;
		for (int i = 1; i <= K && fl; ++i) {
			fl &= (a[i].x1 == a[i].x2);
		}
		if (fl) {
			for (int i = 1; i <= m; ++i) {
				ans[ID(1, i)] = 'D';
				ans[ID(2, i)] = 'U';
			}
			print();
			return;
		}
		if (n == 2) {
			for (int i = 1; i <= m; ++i) {
				fa[i] = i;
			}
			for (int i = 1; i <= K; ++i) {
				if (a[i].y1 > a[i].y2) {
					swap(a[i].y1, a[i].y2);
				}
				for (int j = find(a[i].y1); j < a[i].y2; j = find(j)) {
					fa[j] = j + 1;
				}
			}
			if (find(1) == find(m)) {
				puts("No");
				return;
			}
			for (int i = 1; i <= m; ++i) {
				ans[ID(1, i)] = 'D';
				ans[ID(2, i)] = 'U';
			}
			int x = find(1);
			ans[ID(1, x)] = ans[ID(2, x)] = 'R';
			ans[ID(1, x + 1)] = ans[ID(2, x + 1)] = 'L';
			print();
			return;
		}
		for (int i = 1; i <= n; i += 2) {
			if (i % 4 == 1) {
				for (int j = 1; j <= m - 2; ++j) {
					ans[ID(i, j)] = 'D';
					ans[ID(i + 1, j)] = 'U';
				}
				ans[ID(i, m - 1)] = 'R';
				ans[ID(i, m)] = 'L';
				ans[ID(i + 1, m - 1)] = 'R';
				ans[ID(i + 1, m)] = 'L';
			} else {
				for (int j = 3; j <= m; ++j) {
					ans[ID(i, j)] = 'D';
					ans[ID(i + 1, j)] = 'U';
				}
				ans[ID(i, 1)] = 'R';
				ans[ID(i, 2)] = 'L';
				ans[ID(i + 1, 1)] = 'R';
				ans[ID(i + 1, 2)] = 'L';
			}
		}
		print();
	}
}

int d[maxn], f[maxn];
vector<int> add[maxn], del[maxn];

inline void work(int l, int r) {
	if (n % 2 == 0) {
		for (int i = 1; i <= n; i += 2) {
			for (int j = l; j <= r; ++j) {
				ans[ID(i, j)] = 'D';
				ans[ID(i + 1, j)] = 'U';
			}
		}
	} else {
		for (int i = 1; i <= n - 2; ++i) {
			for (int j = l; j <= r; j += 2) {
				ans[ID(i, j)] = 'R';
				ans[ID(i, j + 1)] = 'L';
			}
		}
		for (int i = l; i <= r; ++i) {
			ans[ID(n - 1, i)] = 'D';
			ans[ID(n, i)] = 'U';
		}
	}
}

void solve() {
	flag = 0;
	scanf("%d%d%d", &n, &m, &K);
	if (n > m) {
		flag = 1;
		swap(n, m);
	}
	bool fl = 1;
	for (int i = 1; i <= K; ++i) {
		scanf("%d%d%d%d%d", &a[i].x1, &a[i].y1, &a[i].x2, &a[i].y2, &a[i].x);
		fl &= a[i].x;
		if (flag) {
			swap(a[i].x1, a[i].y1);
			swap(a[i].x2, a[i].y2);
		}
	}
	if (fl) {
		Sub1::solve();
		return;
	}
	if (n == 1) {
		fl = 1;
		for (int i = 1; i <= K && fl; ++i) {
			int x = (a[i].y1 ^ 1);
			int t = (a[i].y1 == a[i].y2 || x == a[i].y2);
			fl &= (a[i].x == t);
		}
		if (fl) {
			for (int i = 1; i <= m; ++i) {
				putchar((i & 1) ? 'R' : 'L');
			}
		} else {
			puts("No");
		}
		return;
	}
	mems(d, 0);
	mems(f, -0x3f);
	for (int i = 1; i <= K; ++i) {
		int l = min(a[i].y1, a[i].y2), r = max(a[i].y1, a[i].y2);
		// printf("l, r: %d %d\n", l, r);
		if (a[i].x) {
			++d[l + 1];
			--d[r + 1];
		} else {
			f[r] = max(f[r], l);
		}
	}
	for (int i = 1; i <= m; ++i) {
		d[i] += d[i - 1];
		vector<int>().swap(add[i]);
		vector<int>().swap(del[i]);
	}
	set<int> S;
	fl = (f[1] < 0);
	S.insert(0);
	for (int i = 2; i <= m && fl; ++i) {
		int x = *S.begin();
		if (!d[i] && !(n & i & 1) && x != i - 1) {
			add[i].pb(i);
			S.insert(i);
		}
		while (S.size() && *S.begin() <= f[i]) {
			del[i].pb(*S.begin());
			S.erase(S.begin());
		}
		// printf("%d %d\n", i, (int)S.size());
		fl &= (!S.empty());
	}
	if (fl) {
		int p = m;
		for (int i = m; i; --i) {
			if (i == p) {
				work(*S.begin() + 1, i == m ? m : i - 1);
				p = *S.begin() - 1;
				if (p >= 1) {
					for (int j = 1; j <= n; ++j) {
						ans[ID(j, p)] = 'R';
						ans[ID(j, p + 1)] = 'L';
					}
				}
			}
			for (int j : del[i]) {
				S.insert(j);
			}
			for (int j : add[i]) {
				S.erase(j);
			}
		}
		print();
		return;
	}
	flag ^= 1;
	swap(n, m);
	for (int i = 1; i <= K; ++i) {
		swap(a[i].x1, a[i].y1);
		swap(a[i].x2, a[i].y2);
	}
	mems(d, 0);
	mems(f, -0x3f);
	for (int i = 1; i <= K; ++i) {
		int l = min(a[i].y1, a[i].y2), r = max(a[i].y1, a[i].y2);
		if (a[i].x) {
			++d[l + 1];
			--d[r + 1];
		} else {
			f[r] = max(f[r], l);
		}
	}
	for (int i = 1; i <= m; ++i) {
		d[i] += d[i - 1];
		vector<int>().swap(del[i]);
		vector<int>().swap(add[i]);
	}
	S.clear();
	fl = (f[1] < 0);
	S.insert(0);
	for (int i = 2; i <= m && fl; ++i) {
		int x = *S.begin();
		if (!d[i] && !(n & i & 1) && x != i - 1) {
			add[i].pb(i);
			S.insert(i);
		}
		while (S.size() && *S.begin() <= f[i]) {
			del[i].pb(*S.begin());
			S.erase(S.begin());
		}
		fl &= (!S.empty());
	}
	if (fl) {
		int p = m;
		for (int i = m; i; --i) {
			if (i == p) {
				work(*S.begin() + 1, i == m ? m : i - 1);
				p = *S.begin() - 1;
				if (p >= 1) {
					for (int j = 1; j <= n; ++j) {
						ans[ID(j, p)] = 'R';
						ans[ID(j, p + 1)] = 'L';
					}
				}
			}
			for (int j : del[i]) {
				S.insert(j);
			}
			for (int j : add[i]) {
				S.erase(j);
			}
		}
		print();
		return;
	}
	puts("No");
}

int main() {
	int T = 1;
	scanf("%d", &T);
	for (int i = 1; i <= T; ++i) {
		printf("Case #%d: ", i);
		solve();
	}
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 31436kb

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: 4ms
memory: 31052kb

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
DRLRLRLDDD
URLRLRLUUU
Case #2: Yes
DDRLRLDDDD
UURLRLUUUU
Case #3: Yes
RLRLRLDDDD
RLRLRLUUUU
Case #4: Yes
RLRLRLRLDD
RLRLRLRLUU

result:

ok all accept

Test #3:

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

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: 3ms
memory: 29200kb

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
RLDD
DDUU
UURL
Case #4: Yes
DDRL
UURL
RLDD
RLUU

result:

ok all accept

Test #5:

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

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
DDRLRLDDDD
UURLRLUUUU
Case #2: Yes
DDRLRLDDDD
UURLRLUUUU
Case #3: No
Case #4: Yes
DRLRLRLDDD
URLRLRLUUU

result:

ok all accept

Test #6:

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

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: 3ms
memory: 28304kb

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
DDRLDDRLRLRL
UURLUURLRLRL

result:

ok all accept

Test #8:

score: 0
Accepted
time: 6ms
memory: 28884kb

input:

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

output:

Case #1: Yes
DRL
URL
DDD
UUU

result:

ok all accept

Test #9:

score: 0
Accepted
time: 41ms
memory: 32664kb

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
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RLRL
RL...

result:

ok all accept

Test #10:

score: 0
Accepted
time: 33ms
memory: 30908kb

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
DDDDRLDDDRLDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...

result:

ok all accept

Test #11:

score: 0
Accepted
time: 36ms
memory: 30456kb

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
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
R...

result:

ok all accept

Test #12:

score: 0
Accepted
time: 36ms
memory: 30812kb

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
RLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR...

result:

ok all accept

Test #13:

score: 0
Accepted
time: 36ms
memory: 30512kb

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
RLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR...

result:

ok all accept

Test #14:

score: 0
Accepted
time: 43ms
memory: 33620kb

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
DDDDDRL
UUUUURL
DDDDDRL
UUUUURL
DDDDDDD
UUUUUUU
DDDDDRL
UUUUURL
DDDDDDD
UUUUUUU
DDDDDRL
UUUUURL
DDDDDRL
UUUUURL
DDDDDRL
UUUUURL
DDDDDRL
UUUUURL
DDDDDRL
UUUUURL
DDDDDRL
UUUUURL
DDDDDRL
UUUUURL
DDDDDRL
UUUUURL
DDDDDRL
UUUUURL
DDDDDRL
UUUUURL
DDDDDRL
UUUUURL
DDDDDRL
UUUUURL
DDDDDRL
UUUUURL...

result:

ok all accept

Test #15:

score: 0
Accepted
time: 40ms
memory: 30500kb

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
RLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR...

result:

ok all accept

Test #16:

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

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
DDDRLDDDD
UUURLUUUU
DDDRLDDDD
UUURLUUUU
Case #2: Yes
RLRL
RLRL
RLRL
RLRL
RLRL
DDDD
UUUU
RLRL
RLRL
Case #3: Yes
DDDDRLDDD
UUUURLUUU
DDDDRLDDD
UUUURLUUU
Case #4: Yes
RLRL
DDDD
UUUU
RLRL
RLRL
RLRL
DDDD
UUUU
RLRL
Case #5: Yes
RLRL
DDDD
UUUU
RLRL
RLRL
RLRL
DDDD
UUUU
RLRL
Case #6: Yes
RLRL
RL...

result:

ok all accept

Test #17:

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

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
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
DDDDRLDDDD
UUUURLUUUU
Case #2: Yes
DDDRL
UUURL
DDDRL
UUURL
DDDDD
UUUUU
DDDRL
UUURL
DDDRL
UUURL
Case #3: No
Case #4: Yes
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
DDRLRLDDDD
UURLRLUUUU
Case #5: Yes
RLRLRLRLRL
RLRLRLRLRL
RLRLRLRLRL
DDRLDDDDRL
UURLUUUURL
Case #6: Ye...

result:

ok all accept

Test #18:

score: 0
Accepted
time: 16ms
memory: 28548kb

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
RLRL
RLDD
RLUU
Case #2: Yes
RLRL
DDRL
UURL
Case #3: Yes
DRL
URL
DDD
UUU
Case #4: Yes
RLRL
DDRL
UURL
Case #5: Yes
RLRL
RLDD
RLUU
Case #6: Yes
DRL
URL
DDD
UUU
Case #7: Yes
DDD
UUU
DRL
URL
Case #8: Yes
RLRL
DDRL
UURL
Case #9: Yes
RLRL
DDRL
UURL
Case #10: Yes
DDD
UUU
DRL
URL
Case #11: Yes
D...

result:

ok all accept

Extra Test:

score: 0
Extra Test Passed