QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506160#6422. Evil CoordinatePoknikWA 16ms3824kbC++143.9kb2024-08-05 15:45:482024-08-05 15:45:48

Judging History

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

  • [2024-08-05 15:45:48]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:3824kb
  • [2024-08-05 15:45:48]
  • 提交

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();
	
	
}

Details

Tip: Click on the bar to expand more detailed information

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