QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#208769#6422. Evil CoordinatezzzyzzzAC ✓23ms3684kbC++174.3kb2023-10-09 20:49:262023-10-09 20:49:27

Judging History

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

  • [2023-10-09 20:49:27]
  • 评测
  • 测评结果:AC
  • 用时:23ms
  • 内存:3684kb
  • [2023-10-09 20:49:26]
  • 提交

answer

#include<bits/stdc++.h>
#include<sstream>
#include<cassert>
#define fi first
#define se second
#define i128 __int128
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> PII;
const double eps=1e-7;
const int N=5e5+7 ,M=5e5+7, INF=0x3f3f3f3f,mod=1e9+7,mod1=998244353;
const long long int llINF=0x3f3f3f3f3f3f3f3f;
inline ll read() {ll x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=(ll)x*10+c-'0';c=getchar();} return x*f;}
inline void write(ll x) {if(x < 0) {putchar('-'); x = -x;}if(x >= 10) write(x / 10);putchar(x % 10 + '0');}
inline void write(ll x,char ch) {write(x);putchar(ch);}
void stin() {freopen("in_put.txt","r",stdin);freopen("my_out_put.txt","w",stdout);}
bool cmp0(int a,int b) {return a>b;}
template<typename T> T gcd(T a,T b) {return b==0?a:gcd(b,a%b);}
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
void hack() {printf("\n----------------------------------\n");}

int T,hackT;
int n,m,k;
char str[N];

void solve() {
	int x=read(),y=read();
	scanf("%s",str+1);
	n=strlen(str+1);
	int a=0,b=0,c=0,d=0;
	
	for(int i=1;i<=n;i++) {
		if(str[i]=='U') a++;
		else if(str[i]=='D') b++;
		else if(str[i]=='L') c++;
		else if(str[i]=='R') d++;
	}
	
	int endx=d-c,endy=a-b;
	
	// printf("endx = %d,endy = %d\n",endx,endy);
	
	if(x==0&&y==0) printf("Impossible\n");
	else if(x==endx&&y==endy) printf("Impossible\n");
	else {
		if(c==0&&d==0) {
			if(x!=0) printf("%s\n",str+1);
			else {
				if(y>endy&&y>=0) {
					for(int i=1;i<=b;i++) printf("D");
					for(int i=1;i<=a;i++) printf("U");
					printf("\n");
				}else if(y>=endy&&y<=0) {
					printf("Impossible\n");
				}else if(y<=endy&&endy>=0) {
					if(y>=0) printf("Impossible\n");
					else {
						for(int i=1;i<=a;i++) printf("U");
						for(int i=1;i<=b;i++) printf("D");
						printf("\n");
					}
				}else if(y<endy&&endy<=0) {
					for(int i=1;i<=a;i++) printf("U");
					for(int i=1;i<=b;i++) printf("D");
					printf("\n");
				}else printf("Impossible\n");
			}  
		}else if(a==0&&b==0) {
			if(y!=0) printf("%s\n",str+1);
			else {
				if(x>endx&&x>=0) {
					for(int i=1;i<=c;i++) printf("L");
					for(int i=1;i<=d;i++) printf("R");
					printf("\n");
				}else if(x>=endx&&x<=0) {
					printf("Impossible\n");
				}else if(x<=endx&&endx>=0) {
					if(x>=0) printf("Impossible\n");
					else {
						for(int i=1;i<=d;i++) printf("R");
						for(int i=1;i<=c;i++) printf("L");
						printf("\n");
					} 
				}else if(x<endx&&endx<=0) {
					for(int i=1;i<=d;i++) printf("R");
					for(int i=1;i<=c;i++) printf("L");
					printf("\n");
				}else printf("Impossible\n");
			}  
		}else {
			if(x==endx) {
				if(x==0) {
					if(c!=0) printf("L"),c--;
					else if(d!=0) printf("R"),d--;
					for(int i=1;i<=a;i++) printf("U");
					for(int i=1;i<=b;i++) printf("D");
					for(int i=1;i<=c;i++) printf("L");
					for(int i=1;i<=d;i++) printf("R");
					printf("\n");
				}else {
					for(int i=1;i<=a;i++) printf("U");
					for(int i=1;i<=b;i++) printf("D");
					for(int i=1;i<=c;i++) printf("L");
					for(int i=1;i<=d;i++) printf("R");
					printf("\n");
				}
			}else if(y==endy) {
				if(y==0) {
					if(a!=0) printf("U"),a--;
					else if(b!=0) printf("D"),b--;
					for(int i=1;i<=c;i++) printf("L");
					for(int i=1;i<=d;i++) printf("R");
					for(int i=1;i<=a;i++) printf("U");
					for(int i=1;i<=b;i++) printf("D");
					printf("\n");
				}else {
					for(int i=1;i<=c;i++) printf("L");
					for(int i=1;i<=d;i++) printf("R");
					for(int i=1;i<=a;i++) printf("U");
					for(int i=1;i<=b;i++) printf("D");
					printf("\n");
				}
			}else {
				if(x==0) {
					for(int i=1;i<=c;i++) printf("L");
					for(int i=1;i<=d;i++) printf("R");
					for(int i=1;i<=a;i++) printf("U");
					for(int i=1;i<=b;i++) printf("D");
					printf("\n");
				}else {
					for(int i=1;i<=a;i++) printf("U");
					for(int i=1;i<=b;i++) printf("D");
					for(int i=1;i<=c;i++) printf("L");
					for(int i=1;i<=d;i++) printf("R");
					printf("\n"); 
				}
			}
		}
	}
}   

int main() {
    // init();
    // stin();
	// ios::sync_with_stdio(false); 

    scanf("%d",&T);
    // T=1; 
    while(T--) hackT++,solve();
    
    return 0;       
}          

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3576kb

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: 15ms
memory: 3684kb

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:

URRUDD
UUR
Impossible
Impossible
Impossible
RRUUUUUUD
DDLRRRR
UD
Impossible
LLLLRRDD
LLRRUDDD
Impossible
UUDDDDLLR
LL
Impossible
UUUDLRR
Impossible
Impossible
Impossible
LLLLLRRRDD
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
UDLLL
Impossible
ULUUDDD
UUDDRR
Impossi...

result:

ok 11109 cases

Test #3:

score: 0
Accepted
time: 23ms
memory: 3672kb

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:

ULLLLRRRR
LLRR
R
LLLLRRRR
ULR
DU
ULLRR
DDDDUUUU
ULLLLRRRR
LLRR
ULR
R
RUUUDDD
DDDDUUUU
DDDUUU
LLLLLRRRRR
LLLRRR
ULR
U
LLLLRRRR
RUUUUDDDD
RUUUDDD
LLLRRR
DDDDUUUU
R
DDDUUU
DDDUUU
LLLLLRRRRR
DDDDUUUU
DDUU
ULLLLRRRR
DDUU
LLLRRR
ULR
ULR
U
ULR
LLLRRR
LLLLLRRRRR
U
DDDUUU
R
LLLRRR
RUUUUDDDD
RUUUUDDDD
LLLRRR
...

result:

ok 11107 cases