QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#208701#6422. Evil CoordinatezzzyzzzWA 18ms3892kbC++173.7kb2023-10-09 20:05:582023-10-09 20:05:58

Judging History

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

  • [2023-10-09 20:05:58]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:3892kb
  • [2023-10-09 20:05:58]
  • 提交

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=c-d,endy=a-b;
	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) {
					printf("Impossible\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 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) {
					printf("Impossible\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 {
			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 {
				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: 0ms
memory: 3800kb

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: -100
Wrong Answer
time: 18ms
memory: 3892kb

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
LLRUUUUDDD
RRUUUUUUD
DDLRRRR
UD
Impossible
LLLLRRDD
LLRRUDDD
LRR
UUDDDDLLR
Impossible
LLLRRUUDDD
UUUDLRR
Impossible
Impossible
ULRRD
LLLLLRRRDD
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
LLLLRRRRRR
LLLRRRRRUU
UDLLL
R
ULUUDDD
UUDDRR
Impossible
U...

result:

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