QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#202098 | #6422. Evil Coordinate | Scene | WA | 30ms | 3520kb | C++14 | 3.0kb | 2023-10-05 19:21:06 | 2023-10-05 19:21:06 |
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];
bool flag=1;
char mp[4]={'U','D','L','R'};
ll tg[4],sx[4];
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||mx==0&&my==0)
{
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;
}
}
ll isok=1;
for(int f1=0;f1<4;f1++)
for(int f2=0;f2<4;f2++)
for(int f3=0;f3<4;f3++)
for(int f4=0;f4<4;f4++)
{
if(isok==2) break;
memset(tg,0,sizeof(tg));
tg[f1]++,tg[f2]++,tg[f3]++,tg[f4]++;
if(tg[f1]==1&&tg[f2]==1&&tg[f3]==1&&tg[f4]==1)
{
sx[0]=f1,sx[1]=f2,sx[2]=f3,sx[3]=f4;
ll x=0,y=0; isok=1;
for(int i=0;i<4;i++)
{
bool flag=0;
if(sx[i]==0&&mx==x&&y<=my&&my<=y+g[0]) flag=1,isok=0;
if(sx[i]==1&&mx==x&&y-g[1]<=my&&my<=y) flag=1,isok=0;
if(sx[i]==2&&my==y&&x-g[2]<=mx&&mx<=x) flag=1,isok=0;
if(sx[i]==4&&my==y&&x<=mx&&mx<=x+g[3]) flag=1,isok=0;
if(flag) break;
x+=dx[sx[i]]*g[sx[i]]; y+=dy[sx[i]]*g[sx[i]];
}
if(isok)
{
isok=2;
for(int i=0;i<4;i++)
while(g[sx[i]]) pc(mp[sx[i]]),g[sx[i]]--;
pc('\n');
}
}
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3380kb
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
Wrong Answer
time: 30ms
memory: 3520kb
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 UUUUUUDRR DDLRRRR UD Impossible DDLLLLRR UDDDLLRR Impossible UUDDDDLLR LL Impossible UUUDLRR Impossible Impossible Impossible LLLLLDDRRR Impossible LR Impossible Impossible Impossible Impossible Impossible LLLUURRRRR UDLLL Impossible UUUDDDL UUDDRR Impossi...
result:
wrong answer case 28, participant's output goes through forbidden coordinate