QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506139#6422. Evil CoordinatePoknikWA 16ms3768kbC++143.8kb2024-08-05 15:39:172024-08-05 15:39:18

Judging History

This is the latest submission verdict.

  • [2024-08-05 15:39:18]
  • Judged
  • Verdict: WA
  • Time: 16ms
  • Memory: 3768kb
  • [2024-08-05 15:39:17]
  • Submitted

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(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: 3768kb

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: 3756kb

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
RDDDLLUUUU
RRDUUUUUU
RRRRDDL
UD
Impossible
LLLLRRDD
LLURRDDD
Impossible
DDDDUULLR
LL
RRUUImpossible
LDUUURR
Impossible
Impossible
Impossible
LLLLLRRRDD
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
ULLLD
Impossible
UUUDDDL
UUDDRR
RRR...

result:

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