QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#304571#7751. Palindrome PathxlwangWA 0ms3612kbC++143.2kb2024-01-13 21:13:532024-01-13 21:13:53

Judging History

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

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

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;
// const int dx[] = {1, -1, 0, 0};
// const int dy[] = {0, 0, 1, -1};
// const char ch[] = "DURL";
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){
    // cout<<x<<endl;
    int px,py,qx,qy;px=sx,py=sy,qx=tx,qy=ty;
    int ln=0;
    while(check1(px,py,x^1) && check1(qx,qy,x)){
        ++ln;ans+=ch[x^1];
        px+=dx[x^1];qx+=dx[x];
        py+=dy[x^1];qy+=dy[x];
    }
    if(check1(qx,qy,x)) ans+=ch[x^1];
    fr(i,1,ln+1) ans+=ch[x];
    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);
    for(int i=0;i<chg.size();++i) change(chg[i]);
    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: 3612kb

input:

2 2
11
11
1 1 2 2

output:

RURLRUDRLRUURLRDURLRUR

result:

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