QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506088#6422. Evil CoordinateFoedere0WA 18ms3764kbC++232.6kb2024-08-05 15:09:442024-08-05 15:09:45

Judging History

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

  • [2024-08-05 15:09:45]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:3764kb
  • [2024-08-05 15:09:44]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
#include<stack>
#define int long long
//#define endl '\n'
using namespace std;
typedef pair<int,int> PII;
const int N=200200;
int n;
int a[N],b[N];
int x,y;
string s;
int o=0,p=0;
map<char,int> m;
void solve(){
	m.clear();
	cin>>x>>y>>s;
	string ans;
	ans.clear();
	if(x==0&&y==0){
		cout<<"Impossible"<<endl;
		return;
	}
	for(int i=0;i<s.size();i++){
		if(s[i]=='L') o--;
		if(s[i]=='R') o++;
		if(s[i]=='U') p++;
		if(s[i]=='D') p--;
		m[s[i]]++;
	}
	if(o==x&&p==y){
		cout<<"Impossible"<<endl;
		return;
	}
	//cout<<"11"<<endl;
	if(x!=0&&y!=0){
		//cout<<o<<p<<endl;
		if(x>=0){
			while(m['L']){
				ans+='L';
				m['L']--;
			}
		}
		else{
			while(m['R']){
				ans+='R';
				m['R']--;
			}
		}
		if(y>=0){
			while(m['U']){
				ans+='U';
				m['U']--;
			}
		}
		else{
			while(m['D']){
				ans+='D';
				m['D']--;
			}
		}
		while(m['L']) ans+='L',m['L']--;
		while(m['R']) ans+='R',m['R']--;
		while(m['U']) ans+='U',m['U']--;
		while(m['D']) ans+='D',m['D']--;
		cout<<ans<<endl;
		return;
	}
	if(x==0){
		int yy=0;
		bool st=0;
		if(m['L']) ans+='L',m['L']--;
		else if(m['R']) ans+='R',m['R']--;
		else st=1;
		if(y>=0){
			while(m['D']){
			    ans+='D';
			    m['D']--;
			    yy--;
		    }
		}
		else{
			while(m['U']){
			    ans+='U';
			    m['U']--;
			    yy++;
		    }
		}
		while(m['D']){
			ans+='D';
			yy--;
			if(yy==y&&st){
				cout<<"Impossible"<<endl;
				return;
			}
			m['D']--;
		}
		while(m['U']){
		    ans+='U';
		    yy++;
		    if(yy==y&&st){
				cout<<"Impossible"<<endl;
				return;
			}
			 m['U']--;
		}
		while(m['L']) ans+='L', m['L']--;
		while(m['R']) ans+='R', m['R']--;
	}
	else if(y==0){
		int xx=0;
		bool st=0;
		if(m['U']) ans+='U',m['U']--;
		else if(m['D']) ans+='D',m['D']--;
		else st=1;
		//cout<<ans<<endl;
		if(x>=0){
			while(m['L']){
			    ans+='L';
			    xx--;
			    m['L']--;
		    }
		}
		else{
			while(m['R']){
			    ans+='R';
			    xx++;
			     m['R']--;
		    }
		}
		while(m['L']){
			ans+='L';
			xx--;
			if(xx==x&&st){
				cout<<"Impossible"<<endl;
				return;
			}
			 m['L']--;
		}
		while(m['R']){
		    ans+='R';
		    xx++;
		    if(xx==x&&st){
				cout<<"Impossible"<<endl;
				return;
			}
			m['R']--;
		}
		while(m['U']) ans+='U', m['U']--;
		while(m['D']) ans+='D', m['D']--;
	}
	cout<<ans<<endl;
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T=1;
	cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

详细

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:

LLUURRD
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 18ms
memory: 3764kb

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
URU
Impossible
Impossible
RUUUULLDDD
RRUUUUUUD
RRRRLDD
UD
Impossible
LLLLDDRR
LLDDDRRU
Impossible
URLLUDDDD
LL
RRDDDLLLUU
LUUURRD
Impossible
Impossible
ULRRD
LDDLLLLRRR
LULLLRRRR
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LUULLRRRRR
DLLLU
Impossible
ULUUDDD
DDRRUU
Impossible
UR...

result:

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