QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506220#6422. Evil CoordinatePoknikWA 11ms3820kbC++144.4kb2024-08-05 16:02:272024-08-05 16:02:27

Judging History

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

  • [2024-08-05 16:02:27]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3820kb
  • [2024-08-05 16:02:27]
  • 提交

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;
			
			if(R!=x-x1){
				for(int i=0;i<L;i++)cout<<"L";
				for(int i=0;i<D;i++)cout<<"D";
				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<L;i++)cout<<"L";
				for(int i=0;i<D;i++)cout<<"D";
				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;
			
			if(L!=x1-x){
				for(int i=0;i<R;i++){
					cout<<"R";
				}
				for(int i=0;i<D;i++)cout<<"D";
				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<R;i++){
					cout<<"R";
				}
				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";
				cout<<endl;
			}
			else cout<<"Impossible"<<endl;
		}
		else if(x<0&&y<0){
			int x1=R;
			int y1=U;
		
			if(L!=x1-x){
				for(int i=0;i<R;i++){
					cout<<"R";
				}
				for(int i=0;i<U;i++){
					cout<<"U";
				}
				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<R;i++){
					cout<<"R";
				}
				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";
				cout<<endl;
			}
			else cout<<"Impossible"<<endl;
		}
		else if(x>0&&y<0){
			int x1=-L;
			int y1=U;
			
			if(D!=y1-y){
				for(int i=0;i<L;i++)cout<<"L";
				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";
				}
				cout<<endl;
			}
			else if(R!=x-x1){
				for(int i=0;i<L;i++)cout<<"L";
				for(int i=0;i<U;i++){
					cout<<"U";
				}
				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 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;
				}
				else cout<<"Impossible"<<endl;
			}
			else cout<<"Impossible"<<endl;
			
			
			
			
		}
		
		
	}
	
	
	
}
signed main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int t;
	cin>>t;
	while(t--)
	solve();
	
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

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: 11ms
memory: 3820kb

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

result:

wrong answer case 33, participant's output goes through forbidden coordinate