QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506416 | #6422. Evil Coordinate | az | WA | 29ms | 3804kb | C++20 | 3.9kb | 2024-08-05 17:17:31 | 2024-08-05 17:17:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
//#define endl "\n"
#define PII pair<int,int>
#define PIS pair<int,string>
#define fr(i,x,y) for(int i=x,p=y;i<=p;i++)
#define rp(i,x,y) for(int i=x,p=y;i>=p;i--)
map<int,string> mp;
const int N=1e6+10;
const int M=1e2+10;
int mod=998244353;
int xx,yy;
int n,m;
int d[4];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
string ss="";
int fg=0;
string s;
void solve(){
cin>>n>>m;
fr(i,0,3){
d[i]=0;
}
cin>>s;
fr(i,0,s.size()-1){
if(s[i]=='L')d[3]--;
if(s[i]=='R')d[1]++;
if(s[i]=='U')d[0]++;
if(s[i]=='D')d[2]--;
}
mp[0]="U";
mp[1]="R";
mp[2]="D";
mp[3]="L";
if(n==0&&m==0){
cout<<"Impossible"<<endl;
return;
}
int cnt=0,now;
int f[4]={0};
fr(i,0,3){
if(d[i]!=0&&!f[i]){
cnt++;
f[i]=1;
now=i;
}
}
int x=0,y=0;
if(d[0]==0&&d[2]==0){
if(m==0&&n>=min(0ll,d[1]+d[3])&&n<=max(0ll,d[1]+d[3])){
cout<<"Impossible"<<endl;
return;
}else{
if(n>0){
fr(i,1,-d[3])cout<<mp[3];
fr(i,1,d[1])cout<<mp[1];
}else{
fr(i,1,d[1])cout<<mp[1];
fr(i,1,-d[3])cout<<mp[3];
}
cout<<endl;
return;
}
}if(d[1]==0&&d[3]==0){
if(n==0&&(m>=min(0ll,d[0]+d[2]))&&(m<=max(0ll,d[0]+d[2]))){
cout<<"Impossible"<<endl;
return;
}else{
if(m>0){
fr(i,1,-d[2])cout<<mp[2];
fr(i,1,d[0])cout<<mp[0];
}else{
fr(i,1,d[0])cout<<mp[0];
fr(i,1,-d[2])cout<<mp[2];
}cout<<endl;
return;
}
}
// if(cnt==1){
// if(now%2){
// if(m==0&&(n>=min(0ll,d[now])&&n<=max(0ll,d[now]))){
// cout<<"Impossible"<<endl;
// return;
// }else{
// cout<<s<<endl;
// return;
// }
// }
// else{
// if(n==0&&(m>=min(0ll,d[now])&&m<=max(0ll,d[now]))){
// cout<<"Impossible"<<endl;
// return;
// }else{
// cout<<s<<endl;
// return;
// }
// }
// }
fr(i,0,3){
if(i%2)x+=d[i];
else y+=d[i];
}
if(x==n&&y==m){
cout<<"Impossible"<<endl;
return;
}
fr(i,0,3){
if(d[i]<0){
d[i]=-d[i];
}
}
int p=0;
x=0,y=0;
if(n>0){
fr(i,1,d[3])cout<<"L";
p+=d[3];
x-=d[3];
d[3]=0;
}else{
fr(i,1,d[1])cout<<"R";
p+=d[1];
x+=d[1];
d[1]=0;
}
if(m>0){
fr(i,1,d[2])cout<<"D";
p+=d[2];
y-=d[2];
d[2]=0;
}else{
fr(i,1,d[0])cout<<"U";
p+=d[0];
y+=d[0];
d[0]=0;
}
if(d[1]){
int t=min(n-x-1,d[1]);
t=max(0ll,t);
fr(i,1,t)cout<<mp[1];
d[1]-=t;
if(d[0]&&d[0]!=m-y){
fr(i,1,d[0])cout<<mp[0];
fr(i,1,d[1])cout<<mp[1];
d[0]=d[1]=0;
}else if(d[0]){
fr(i,1,d[1])cout<<mp[1];
fr(i,1,d[0])cout<<mp[0];
d[0]=d[1]=0;
}
if(d[2]&&d[2]!=y-m){
fr(i,1,d[2])cout<<mp[2];
fr(i,1,d[1])cout<<mp[1];
d[2]=d[1]=0;
}else if(d[2]){
fr(i,1,d[1])cout<<mp[1];
fr(i,1,d[2])cout<<mp[2];
d[2]=d[1]=0;
}
}else if(d[3]){
int t=min(x-n-1,d[3]);
t=max(0ll,t);
fr(i,1,t)cout<<mp[3];
d[3]-=t;
if(d[0]&&d[0]!=m-y){
fr(i,1,d[0])cout<<mp[0];
fr(i,1,d[3])cout<<mp[3];
d[0]=d[3]=0;
}else if(d[0]){
fr(i,1,d[3])cout<<mp[3];
fr(i,1,d[0])cout<<mp[0];
d[0]=d[3]=0;
}
if(d[2]&&d[2]!=y-m){
fr(i,1,d[2])cout<<mp[2];
fr(i,1,d[3])cout<<mp[3];
d[2]=d[3]=0;
}else if(d[2]){
fr(i,1,d[3])cout<<mp[3];
fr(i,1,d[2])cout<<mp[2];
d[2]=d[3]=0;
}
}
else{
if(d[0]&&d[0]!=m-y){
fr(i,1,d[0])cout<<mp[0];
fr(i,1,d[3])cout<<mp[3];
d[3]=d[0]=0;
}else if(d[0]){
fr(i,1,d[3])cout<<mp[3];
fr(i,1,d[0])cout<<mp[0];
d[3]=d[0]=0;
}
if(d[2]&&d[2]!=y-m){
fr(i,1,d[2])cout<<mp[2];
fr(i,1,d[3])cout<<mp[3];
d[2]=d[3]=0;
}else if(d[2]){
fr(i,1,d[3])cout<<mp[3];
fr(i,1,d[2])cout<<mp[2];
d[2]=d[3]=0;
}
}
cout<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n=1;
cin>>n;
while(n--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLDRRUU UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: -100
Wrong Answer
time: 29ms
memory: 3804kb
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:
UURRDD UUR Impossible Impossible Impossible RRDUUUUUU RRRRDDL UD Impossible LLLLRRDD LLURRDDD Impossible RUULDDDDL LL Impossible LDRUUUR Impossible Impossible Impossible RRRLLLLLDD Impossible RL Impossible Impossible Impossible Impossible Impossible RRRRRLLLUU ULLLD Impossible UUULDDD UURDDR Impossi...
result:
wrong answer case 107, participant's output is not a permutation of the input