QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506160 | #6422. Evil Coordinate | Poknik | WA | 16ms | 3824kb | C++14 | 3.9kb | 2024-08-05 15:45:48 | 2024-08-05 15:45:48 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
void solve()
{
int x,y;
cin>>x>>y;
string s;
cin>>s;
int R,L,U,D;
R = count(s.begin(), s.end(), 'R');
L = count(s.begin(), s.end(), 'L');
U = count(s.begin(), s.end(), 'U');
D = count(s.begin(), s.end(), 'D');
if(x==0&&y==0)cout<<"Impossible"<<endl;
else if(R-L==x&&U-D==y)cout<<"Impossible"<<endl;
else{
if(x>0&&y>0){
int x1=-L;
int y1=-D;
for(int i=0;i<L;i++)cout<<"L";
for(int i=0;i<D;i++)cout<<"D";
if(R!=x-x1){
for(int i=0;i<R;i++){
cout<<"R";
}
for(int i=0;i<U;i++){
cout<<"U";
}
cout<<endl;
}
else if(U!=y-y1){
for(int i=0;i<U;i++){
cout<<"U";
}
for(int i=0;i<R;i++){
cout<<"R";
}
cout<<endl;
}
else cout<<"Impossible"<<endl;
}
else if(x<0&&y>0){
int x1=R;
int y1=-D;
for(int i=0;i<R;i++){
cout<<"R";
}
for(int i=0;i<D;i++)cout<<"D";
if(L!=x-x1){
for(int i=0;i<L;i++)cout<<"L";
for(int i=0;i<U;i++){
cout<<"U";
}
cout<<endl;
}
else if(U!=y-y1){
for(int i=0;i<U;i++){
cout<<"U";
}
for(int i=0;i<L;i++)cout<<"L";
cout<<endl;
}
else cout<<"Impossible"<<endl;
}
else if(x<0&&y<0){
int x1=R;
int y1=U;
for(int i=0;i<R;i++){
cout<<"R";
}
for(int i=0;i<U;i++){
cout<<"U";
}
if(L!=x1-x){
for(int i=0;i<L;i++)cout<<"L";
for(int i=0;i<D;i++)cout<<"D";
cout<<endl;
}
else if(D!=y1-y){
for(int i=0;i<D;i++)cout<<"D";
for(int i=0;i<L;i++)cout<<"L";
cout<<endl;
}
else cout<<"Impossible"<<endl;
}
else if(x>0&&y<0){
int x1=-L;
int y1=U;
for(int i=0;i<L;i++)cout<<"L";
for(int i=0;i<U;i++){
cout<<"U";
}
if(D!=y1-y){
for(int i=0;i<D;i++)cout<<"D";
for(int i=0;i<R;i++){
cout<<"R";
}
cout<<endl;
}
else if(R!=x-x1){
for(int i=0;i<R;i++){
cout<<"R";
}
for(int i=0;i<D;i++)cout<<"D";
cout<<endl;
}
else cout<<"Impossible"<<endl;
}
else{
if(x==0){
if(L!=R){for(int i=0;i<L;i++)cout<<"L";
for(int i=0;i<R;i++){
cout<<"R";
}
for(int i=0;i<D;i++)cout<<"D";
for(int i=0;i<U;i++){
cout<<"U";
}
cout<<endl;}
else if(y>0){
if(U-D<y){
for(int i=0;i<L;i++)cout<<"L";
for(int i=0;i<R;i++){
cout<<"R";
}
for(int i=0;i<D;i++)cout<<"D";
for(int i=0;i<U;i++){
cout<<"U";
}
cout<<endl;
}
else cout<<"Impossible"<<endl;
}
else if(y<0){
if(U-D>y){
for(int i=0;i<L;i++)cout<<"L";
for(int i=0;i<R;i++){
cout<<"R";
}for(int i=0;i<U;i++){
cout<<"U";
}for(int i=0;i<D;i++)cout<<"D";
cout<<endl;
}
else cout<<"Impossible"<<endl;
}
}
else if(y==0){
if(U!=D){
for(int i=0;i<D;i++)cout<<"D";
for(int i=0;i<U;i++){
cout<<"U";
}
for(int i=0;i<L;i++)cout<<"L";
for(int i=0;i<R;i++){
cout<<"R";
}
cout<<endl;
}
else if(x>0){
if(R-L<x){
for(int i=0;i<U;i++){
cout<<"U";
}for(int i=0;i<D;i++)cout<<"D";
for(int i=0;i<L;i++)cout<<"L";
for(int i=0;i<R;i++){
cout<<"R";
}
cout<<endl;
}
else cout<<"Impossible"<<endl;
}
else if(x<0){
if(L-R>x){
for(int i=0;i<U;i++){
cout<<"U";
}for(int i=0;i<D;i++)cout<<"D";
for(int i=0;i<R;i++){
cout<<"R";
}for(int i=0;i<L;i++)cout<<"L";
cout<<endl;
}
else cout<<"Impossible"<<endl;
}
}
}
}
}
signed main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
cin>>t;
while(t--)
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLDRRUU UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: -100
Wrong Answer
time: 16ms
memory: 3780kb
input:
11109 6 0 RUDUDR 2 0 URU 0 0 UDRU 0 0 R -1 1 LDUUDDRUUL -1 5 RRUUUDUUU -8 4 RRDRLDR 2 0 UD 0 0 UUDD 3 -2 LDDLLLRR 3 -2 LDRURLDD 1 0 RRL -1 0 DUDDLLRDU -4 0 LL -1 -1 DLRLDLUDUR 1 4 URDULUR 0 0 DDUUDUDDDD 0 2 UU 1 0 RRULD 0 -2 LDLRLLDRRL 0 1 RLRLLRLUR -3 0 RL 0 0 D 0 0 L 0 0 DDLRRUDRUD 0 0 DULU 2 0 RR...
output:
UUDDRR UUR Impossible Impossible Impossible RRDUUUUUU RRRRDDL UD Impossible LLLLRRDD LLURRDDD Impossible DDDDUULLR LL Impossible LDUUURR Impossible Impossible Impossible LLLLLRRRDD Impossible RL Impossible Impossible Impossible Impossible Impossible LLLRRRRRUU ULLLD Impossible UUUDDDL UUDDRR Impossi...
result:
wrong answer case 61, participant does not find an answer but the jury does