QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#304563#7751. Palindrome PathxlwangWA 0ms3776kbC++143.0kb2024-01-13 21:07:162024-01-13 21:07:16

Judging History

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

  • [2024-01-13 21:07:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3776kb
  • [2024-01-13 21:07:16]
  • 提交

answer

#include<bits/stdc++.h>
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define randfind(l,r) (rnd()%((r)-(l)+1)+(l))
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
using namespace std;
inline int read(){
	int x=0;
	bool f=0;
	char c=getchar();
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
inline void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
//inline void init(){
//	int t=read();
//	while(t--) work();
//}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int Maxn=50;
char c[Maxn][Maxn];
int n,m;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
char ch[]="RLUD";
inline bool check(int x,int y){
    if(!(x>=1 && x<=n && y>=1 && y<=m)) return false;
    return true;
}
int vis[Maxn][Maxn];
int sx,sy,tx,ty;
inline bool check1(int nx,int ny,int d){
    if(check(nx+dx[d],ny+dy[d]) && c[nx+dx[d]][ny+dy[d]]=='1') return true;
    return false;
}
string ans;
int num;
inline void change(int x){
    int px,py,qx,qy;px=sx,py=sy,qx=tx,qy=ty;
    int ln=0;
    while(check1(px,py,x) && check1(qx,qy,x)){
        ++ln;ans+=ch[x];
        px+=dx[x];qx+=dx[x];
        py+=dy[x];qy+=dy[x];
    }
    if(check1(qx,qy,x)) ans+=ch[x^1];
    fr(i,1,ln+1) ans+=ch[x^1];
    sx+=dx[x];sy+=dy[x];
}
inline void dfs(int x,int y){
    ++num;
    fr(i,0,3){
        int nx,ny;
        nx=x+dx[i];
        ny=y+dy[i];
        if(!check(nx,ny)) continue;
        if(c[nx][ny]=='0') continue;
        if(vis[nx][ny]) continue;
        vis[nx][ny]=1;
        change(i);dfs(nx,ny);
        change(i^1);
    }
}
vector<int> chg;
inline bool dfs2(int x,int y){
    if(x==tx && y==ty) return true;
    fr(i,0,3){
        int nx,ny;
        nx=x+dx[i];ny=y+dy[i];
        if(!check(nx,ny)) continue;
        if(c[nx][ny]=='0') continue;
        if(vis[nx][ny]) continue;
        vis[nx][ny]=1;
        chg.push_back(i);
        if(dfs2(nx,ny)) return true;
        chg.pop_back();
    }
    return false;
}
inline void init(){
    n=read();m=read();
    fr(i,1,n) scanf("%s",c[i]+1);
    sx=read();sy=read();tx=read();ty=read();
}
inline void work(){
    vis[sx][sy]=1;
    dfs(sx,sy);
    // cout<<num<<endl;
    fr(i,1,n) fr(j,1,m){
        if(c[i][j]=='0') continue;
        --num;vis[i][j]=0;
    }
    if(num!=0){
        puts("-1");
        return;
    }
    vis[sx][sy]=1;
    dfs2(sx,sy);
    while(!chg.empty()) change(chg.back()),chg.pop_back();
    cout<<ans;
    reverse(ans.begin(),ans.end());
    cout<<ans;
    puts("");
}
signed main(){
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
    init();work();
    // printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3776kb

input:

2 2
11
11
1 1 2 2

output:

LDLRRLDUULRRDLLDRRLUUDLRRLDL

result:

wrong answer End Point Is (2,1), Not (er = 2, ec = 2)