QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#682774 | #6422. Evil Coordinate | QF_love_younger_sister | WA | 20ms | 3748kb | C++23 | 5.6kb | 2024-10-27 17:19:20 | 2024-10-27 17:19:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
//#define int long long
string ss;
map<char,pair<int,int> > mp;
map<pair<int,int> ,char> hy;
signed main(){
ios_base::sync_with_stdio(false),cin.tie(0);
int n,k;
int t;
mp['R']={1,0};
mp['L']={-1,0};
mp['D']={0,-1};
mp['U']={0,1};
// hy[{1,0}]='R';
// hy[{-1,0}]='L';
// hy[{0,-1}]='D';
// hy[{0,1}]='U';
cin >> t;
while(t--){
int n,xq,yq;
cin >> xq >> yq;
cin >> ss;
int len=ss.size();
int s=0,x=0,z=0,y=0;
for(int i=0; i<len; i++){
pair<int,int> qf=mp[ss[i]];
if(qf.first==1){
y++;
}
if(qf.first==-1){
z++;
}
if(qf.second==1){
s++;
}
if(qf.second==-1){
x++;
}
}
// cout << s << " " << x << " " << z << " " << y << "\n";
if((y-z==xq && s-x==yq)){
cout << "Impossible\n";
continue;
}
// if(z==0 && y==0 && yq==0){
// if(xq>=0 && s>=x+xq){
// cout << "Impossible\n";
// continue;
// }
// if(xq<=0 && x-s>=abs(xq)){
// cout << "Impossible\n";
// continue;
// }
// }
// if(s==0 && x==0 && xq==0){
// if(yq>=0 && z>=y+yq){
// cout << "Impossible\n";
// continue;
// }
// if(yq<=0 && y-z>=abs(yq)){
// cout << "Impossible\n";
// continue;
// }
// }
if(xq==0 && yq==0){
cout << "Impossible\n";
continue;
}
if(xq!=0 && yq!=0){
int mdx=y-z,mdy=s-x;
int wzx=0,wzy=0;
if(mdx==xq){
while(s!=0){
s--;
cout << "U";
}
while(x!=0){
x--;
cout << "D";
}
while(z!=0){
z--;
cout << "L";
}
while(y!=0){
y--;
cout << "R";
}
}
else{
while(z!=0){
z--;
cout << "L";
}
while(y!=0){
y--;
cout << "R";
}
while(s!=0){
s--;
cout << "U";
}
while(x!=0){
x--;
cout << "D";
}
}
}
if(xq!=0 && yq==0){
if(s==0 && x==0 && yq==0){
if(xq>=0 && y>=2*z+xq){
cout << "Impossible\n";
continue;
}
if(xq<=0 && z-2*y>=abs(xq)){
cout << "Impossible\n";
continue;
}
}
if(xq>0){
int wz=0,flag=1;
if(wz!=yq&&flag){
while(z!=0){
z--;
cout << "L";
}
while(y!=0){
y--;
cout << "R";
}
flag=0;
}
while(s!=0){
s--;
wz++;
cout << "U";
if(wz!=yq&&flag){
while(z!=0){
z--;
cout << "L";
}
while(y!=0){
y--;
cout << "R";
}
flag=0;
}
}
while(x!=0){
x--;
wz--;
cout << "D";
if(wz!=yq&&flag){
while(z!=0){
z--;
cout << "L";
}
while(y!=0){
y--;
cout << "R";
}
flag=0;
}
}
if(flag){
while(z!=0){
z--;
cout << "L";
}
while(y!=0){
y--;
cout << "R";
}
flag=0;
}
}
else{
int wz=0,flag=1;
if(wz!=yq&&flag){
while(z!=0){
z--;
cout << "L";
}
while(y!=0){
y--;
cout << "R";
}
flag=0;
}
while(s!=0){
s--;
wz++;
cout << "U";
if(wz!=yq&&flag){
while(y!=0){
y--;
cout << "R";
}
while(z!=0){
z--;
cout << "L";
}
flag=0;
}
}
while(x!=0){
x--;
wz--;
cout << "D";
if(wz!=yq&&flag){
while(y!=0){
y--;
cout << "R";
}
while(z!=0){
z--;
cout << "L";
}
flag=0;
}
}
if(flag){
while(y!=0){
y--;
cout << "R";
}
while(z!=0){
z--;
cout << "L";
}
flag=0;
}
}
}
if(xq==0 && yq!=0){
if(z==0 && y==0 && xq==0){
if(yq>=0 && s-2*x>=yq){
cout << "Impossible\n";
continue;
}
if(yq<=0 && x-2*s>=abs(yq)){
cout << "Impossible\n";
continue;
}
}
if(yq>0){
int wz=0,flag=1;
if(wz!=xq && flag){
flag=0;
while(x!=0){
x--;
cout << "D";
}
while(s!=0){
s--;
cout << "U";
}
}
while(y!=0){
y--;
cout << "R";
wz++;
if(wz!=xq && flag){
flag=0;
while(x!=0){
x--;
cout << "D";
}
while(s!=0){
s--;
cout << "U";
}
}
}
while(z!=0){
z--;
cout << "L";
wz--;
if(wz!=xq && flag){
flag=0;
while(x!=0){
x--;
cout << "D";
}
while(s!=0){
s--;
cout << "U";
}
}
}
if(flag){
while(x!=0){
x--;
cout << "D";
}
while(s!=0){
s--;
cout << "U";
}
}
}
else{
int wz=0,flag=1;
if(wz!=xq && flag){
flag=0;
while(x!=0){
x--;
cout << "D";
}
while(s!=0){
s--;
cout << "U";
}
}
while(y!=0){
y--;
cout << "R";
wz++;
if(wz!=xq && flag){
flag=0;
while(s!=0){
s--;
cout << "U";
}
while(x!=0){
x--;
cout << "D";
}
}
}
while(z!=0){
z--;
cout << "L";
wz--;
if(wz!=xq && flag){
flag=0;
while(s!=0){
s--;
cout << "U";
}
while(x!=0){
x--;
cout << "D";
}
}
}
if(flag){
while(s!=0){
s--;
cout << "U";
}
while(x!=0){
x--;
cout << "D";
}
}
}
}
cout << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
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: 20ms
memory: 3748kb
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 Impossible RRUUUUUUD LRRRRDD UD Impossible LLLLRRDD LLRRUDDD Impossible URLLUDDDD LL Impossible UUUDLRR Impossible Impossible Impossible RDDRRLLLLL Impossible RL Impossible Impossible Impossible Impossible Impossible RUURRRRLLL LLLUD Impossible ULUUDDD UUDDRR Impossi...
result:
wrong answer case 13, participant's output goes through forbidden coordinate