QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506433#6422. Evil CoordinatePoknikAC ✓21ms4052kbC++141.1kb2024-08-05 17:24:232024-08-05 17:24:24

Judging History

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

  • [2024-08-05 17:24:24]
  • 评测
  • 测评结果:AC
  • 用时:21ms
  • 内存:4052kb
  • [2024-08-05 17:24:23]
  • 提交

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]={0,1,2,3};
	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();
	
	
}

詳細信息

Test #1:

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

input:

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

output:

LLRRUUD
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: 0
Accepted
time: 16ms
memory: 4052kb

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:

RRUUDD
RUU
Impossible
Impossible
Impossible
RRUUUUUUD
LRRRRDD
UD
Impossible
LLLLRRDD
LLRRUDDD
Impossible
RUUDDDDLL
LL
Impossible
LRRUUUD
Impossible
Impossible
Impossible
LLLLLRRRDD
Impossible
LR
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
LLLUD
Impossible
LUUUDDD
RRUUDD
Impossi...

result:

ok 11109 cases

Test #3:

score: 0
Accepted
time: 21ms
memory: 3904kb

input:

11107
1 0
LLRLRURLR
1 0
LLRR
0 1
R
1 0
LLLRLRRR
1 0
RUL
0 1
UD
1 0
RLRLU
0 1
DDDUUUDU
1 0
RURRLLRLL
1 0
LRLR
1 0
ULR
0 1
R
0 1
DDUUUDR
0 1
UUDDUDDU
0 1
DDUUDU
1 0
RRLRLLRLRL
1 0
RLRRLL
1 0
LUR
1 0
U
1 0
LRRRLLLR
0 1
DRUUDDUDU
0 1
DUUDDUR
1 0
LRLRLR
0 1
UUDDDUDU
0 1
R
0 1
UDUDDU
0 1
DUUDUD
1 0
RRLRRR...

output:

LLLLRRRRU
LLRR
R
LLLLRRRR
LRU
DU
LLRRU
DDDDUUUU
LLLLRRRRU
LLRR
LRU
R
RUUUDDD
DDDDUUUU
DDDUUU
LLLLLRRRRR
LLLRRR
LRU
U
LLLLRRRR
RUUUUDDDD
RUUUDDD
LLLRRR
DDDDUUUU
R
DDDUUU
DDDUUU
LLLLLRRRRR
DDDDUUUU
DDUU
LLLLRRRRU
DDUU
LLLRRR
LRU
LRU
U
LRU
LLLRRR
LLLLLRRRRR
U
DDDUUU
R
LLLRRR
RUUUUDDDD
RUUUUDDDD
LLLRRR
...

result:

ok 11107 cases