QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506420#6422. Evil CoordinatePoknikWA 0ms3528kbC++141.1kb2024-08-05 17:20:062024-08-05 17:20:07

Judging History

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

  • [2024-08-05 17:20:07]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3528kb
  • [2024-08-05 17:20:06]
  • 提交

answer

#include<bits/stdc++.h>
#define int  long long
using namespace std;
int dx[]={-1,1,0,0},dy[]={0,0,1,-1};
char d[]={'L','R','U','D'};
void solve()
{
	int mx,my;
	string s;
	cin>>mx>>my>>s;
	int a[4]={0,0,0,0};
	int x=0,y=0;
	int next[4]={1,2,3,4};
	int f=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='L')a[0]++,x--;
		if(s[i]=='R')a[1]++,x++;
		if(s[i]=='U')a[2]++,y++;
		if(s[i]=='D')a[3]++,y--;
	}
	if((mx==0&&my==0)||(mx==x&&my==y)){
		cout<<"Impossible"<<endl;
	}
	else{
		do{
		int flag=0;
		x=y=0;
		for(int i=0;i<4;i++){
			for(int j=1;j<=a[next[i]];j++){
				x+=dx[next[i]],y+=dy[next[i]];
				if(x==mx&&y==my){
					flag=1;break;
				}
			}
			if(flag)break;
		}
		if(!flag){
			f=1;
			for(int i=0;i<4;i++){
				for(int j=0;j<a[next[i]];j++){
					cout<<d[next[i]];
				}
			}
			cout<<endl;
			break;
		}
		}while(next_permutation(next,next+4));
		if(f==0){
			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: 0
Wrong Answer
time: 0ms
memory: 3528kb

input:

5
1 1
RURULLD
0 5
UUU
0 3
UUU
0 2
UUU
0 0
UUU

output:

RRUUD

result:

wrong answer Line "RRUUD