QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#202042 | #6422. Evil Coordinate | Scene | TL | 0ms | 3416kb | C++14 | 2.5kb | 2023-10-05 18:44:24 | 2023-10-05 18:44:24 |
Judging History
answer
#include<bits/stdc++.h>
#define fo(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
#define Ts template<typename Ty,typename... Ar>
#define Tp template<typename Ty>
#define isdigit(c) ((c)>='0'&&(c)<='9')
#define ll long long
#define RS register
#define gc getchar
#define pc putchar
#define I inline
using namespace std;
Tp I Ty wmax(Ty a,Ty b){return a>=b? a:b;}
Tp I Ty wmin(Ty a,Ty b){return a<=b? a:b;}
namespace WrongIO
{
Tp I void read(Ty &x){x=0;Ty opt=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();if(c=='-')opt=-1,c=gc();while(isdigit(c))x=(x<<3)+(x<<1),x+=c-'0',c=gc();x*=opt;return;}
Tp I void write(Ty x){short OI_USE[50],OI_top=0;if(x<=0) if(x==0)pc('0');else pc('-'),x*=-1;while(x)OI_USE[++OI_top]=x%10,x/=10;while(OI_top--)pc(OI_USE[OI_top+1]+'0');return;}
I void writec(char c[]){int len=strlen(c);for(int i=0;i<len;i++)pc(c[i]);}
I void writes(string s){int len=s.length();for(int i=0;i<len;i++)pc(s[i]);}
I void readc(char &c,int l,int r){c=gc(); while(c!=EOF&&(c<l||c>r)) c=gc();}
I void readc(char &c,char val){c=gc();while(c!=EOF&&c!=val) c=gc();}
I void readc(char val){char c;c=gc();while(c!=EOF&&c!=val) c=gc();}
I void readls(string &s){char c=gc();while(c!='\n') s.push_back(c),c=gc();}
Ts I void read(Ty &x,Ar &...y) {read(x),read(y...);}
} using namespace WrongIO;
ll T,mx,my,len;
ll dx[4]={0,0,-1,1},dy[4]={1,-1,0,0},g[4];
ll sx[100050];
bool flag=1;
char mp[4]={'U','D','L','R'};
void dfs(ll x,ll y,ll dep)
{
if(flag==0) return;
if(x==mx&&y==my) return;
if(dep==len+1)
{
for(int i=1;i<=len;i++)
pc(mp[sx[i]]);
flag=0; pc('\n');
return;
}
for(int i=0;i<4;i++)
{
if(g[i]==0) continue;
g[i]-=1; sx[dep]=i;
ll tx=x+dx[i],ty=y+dy[i];
dfs(tx,ty,dep+1);
if(flag==0) return;
g[i]+=1;
}
}
int main()
{
read(T);
while(T--)
{
flag=1;
string s;
cin>>mx>>my>>s;
len=s.length();
memset(g,0,sizeof(g));
for(int i=0;i<len;i++)
{
if(s[i]=='U') g[0]++;
if(s[i]=='D') g[1]++;
if(s[i]=='L') g[2]++;
if(s[i]=='R') g[3]++;
}
ll x=g[3]-g[2],y=g[0]-g[1];
if(mx==x&&my==y)
{
writes("Impossible\n");
continue;
}
if((g[0]==0)+(g[1]==0)+(g[2]==0)+(g[3]==0)==3)
{
bool flag=0;
if(g[0]!=0&&mx==0&&0<=my&&my<=g[0]) flag=1;
if(g[1]!=0&&mx==0&&-g[1]<=my&&my<=0) flag=1;
if(g[2]!=0&&my==0&&-g[2]<=mx&&mx<=0) flag=1;
if(g[3]!=0&&my==0&&0<=mx&&mx<=g[3]) flag=1;
if(flag)
{
writes("Impossible\n");
continue;
}
}
dfs(0,0,1);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3416kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
UUDLLRR UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: -100
Time Limit Exceeded
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 UUUUUUDRR DDLRRRR UD Impossible DDLLLLRR UDDDLLRR Impossible UUDDDDLLR LL Impossible UUUDLRR Impossible Impossible DLDLLLLRRR Impossible LR Impossible Impossible Impossible ULLLRRRRUR UDLLL Impossible UUUDDDL UUDDRR Impossible UUDDLRR UUUDUDURR UUUDLRRRRR DLLRRR DDDD...