QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644624#6422. Evil Coordinaterush-from-behind#AC ✓29ms3692kbC++172.1kb2024-10-16 14:51:392024-10-16 14:51:39

Judging History

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

  • [2024-10-16 14:51:39]
  • 评测
  • 测评结果:AC
  • 用时:29ms
  • 内存:3692kb
  • [2024-10-16 14:51:39]
  • 提交

answer

#include <bits/stdc++.h>
#define F(i,x,y) for(int i=(x);i<=(y);i++)
#define DF(i,x,y) for(int i=(x);i>=(y);i--)
#define ms(x,y) memset(x,y,sizeof(x))
#define SZ(x) (int)x.size()-1
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int,int> pii;
template<typename T> void chkmax(T &x,T y){ x=max(x,y);}
template<typename T> void chkmin(T &x,T y){ x=min(x,y);}
template<typename T> void read(T &FF){
    FF=0;int RR=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') RR=-1;
    for(;isdigit(ch);ch=getchar()) FF=(FF<<1)+(FF<<3)+ch-48;
    FF*=RR;
}
int c[4];
int ord[4];
int fx[4][2]={{0,1},{0,-1},{-1,0},{1,0}};
char dy[4]={'U','D','L','R'};
void work(){
    int mx,my;cin>>mx>>my;
    string opt;cin>>opt;
    ms(c,0);
    F(i,0,SZ(opt)){
        if(opt[i]=='U') c[0]++;
        if(opt[i]=='D') c[1]++;
        if(opt[i]=='L') c[2]++;
        if(opt[i]=='R') c[3]++;
    }
    int tx=c[3]-c[2],ty=c[0]-c[1];
    if(tx==mx&&ty==my){ cout<<"Impossible"<<'\n';return;}
    if(!mx&&!my){ cout<<"Impossible"<<'\n';return;}
    // cout<<tx<<' '<<ty<<'\n';
    bool fl;
    if(mx==0) fl=0;
    else if(my==0) fl=1;
    else{
        if(mx==tx) fl=1;
        else if(my==ty) fl=0;
        else fl=0;
    }
    if(!fl){
        if(tx>=mx) ord[0]=3,ord[2]=2;
        else ord[0]=2,ord[2]=3;
        if(ty>=my) ord[1]=0,ord[3]=1;
        else ord[1]=1,ord[3]=0;
    }
    else{
        if(ty>=my) ord[0]=0,ord[2]=1;
        else ord[0]=1,ord[2]=0;
        if(tx>=mx) ord[1]=3,ord[3]=2;
        else ord[1]=2,ord[3]=3;
    }
    // F(i,0,3) cout<<ord[i]<<' ';cout<<'\n';
    int x=0,y=0;
    F(i,0,3){
        // cout<<fx[ord[i]][0]<<' '<<fx[ord[i]][1]<<'\n';
        F(j,1,c[ord[i]]){
            x+=fx[ord[i]][0],y+=fx[ord[i]][1];
            if(x==mx&&y==my){ cout<<"Impossible"<<'\n';return;}
        }
    }
    F(i,0,3) F(j,1,c[ord[i]]) cout<<dy[ord[i]];
    cout<<'\n';
}
int main(){
    int T;cin>>T;
    while(T--) work();    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3540kb

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: 0
Accepted
time: 25ms
memory: 3692kb

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:

UUDDRR
UUR
Impossible
Impossible
Impossible
RRUUUUUUD
RRRRDDL
UD
Impossible
LLLLRRDD
LLURRDDD
Impossible
DDDDRUULL
LL
Impossible
DRRUUUL
Impossible
Impossible
Impossible
LLLLLRRRDD
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
RRRRRUULLL
ULLLD
Impossible
UUUDDDL
UURRDD
Impossi...

result:

ok 11109 cases

Test #3:

score: 0
Accepted
time: 29ms
memory: 3688kb

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
RDDDUUU
DDDDUUUU
DDDUUU
LLLLLRRRRR
LLLRRR
ULR
U
LLLLRRRR
RDDDDUUUU
RDDDUUU
LLLRRR
DDDDUUUU
R
DDDUUU
DDDUUU
LLLLLRRRRR
DDDDUUUU
DDUU
ULLLLRRRR
DDUU
LLLRRR
ULR
ULR
U
ULR
LLLRRR
LLLLLRRRRR
U
DDDUUU
R
LLLRRR
RDDDDUUUU
RDDDDUUUU
LLLRRR
...

result:

ok 11107 cases