QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#638741#7751. Palindrome Pathzzuqy#Compile Error//C++142.6kb2024-10-13 16:48:122024-10-13 16:48:17

Judging History

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

  • [2024-10-13 16:48:17]
  • 评测
  • [2024-10-13 16:48:12]
  • 提交

answer

#include<bits/stdc++.h>
#define N 39
using namespace std;
bool vst[N][N];
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};
char dir[4]={'U','D','L','R'};
char c[N][N];
string ans,ans2,mid; 
int n,m;
bool ok(int x,int y){
	if(x<1||x>n||y<1||y>m)return 0;
	if(c[x][y]=='0')return 0;
	return 1;
}
void dfs(int x,int y){
	vst[x][y]=1;
	for(int k=0;k<4;k++){
		int nx=x+dx[k],ny=y+dy[k];
		if(!ok(nx,ny))continue;
		if(vst[nx][ny])continue;
		ans+=dir[k];
		dfs(nx,ny);
		ans+=dir[k^1];
	}
}
void move(int &x,int &y,int dir){
	int nx=x+dx[dir],ny=y+dy[dir];
	if(ok(x,y))x=nx,y=ny;
}
void move(int &x,int &y,char dir){
	if(dir=='U')move(x,y,0);
	if(dir=='D')move(x,y,1);
	if(dir=='L')move(x,y,2);
	if(dir=='R')move(x,y,3);
}
int sx,sy,tx,ty;
struct node{
	int x1,y1,x2,y2;
	/*
	bool operator ==(const node&a){
		return x1==a.x1&&y1==a.y1&&x2==a.x2&&y2==a.y2;
	}*/
	bool operator !=(const node&a){
		return x1!=a.x1||y1!=a.y1||x2!=a.x2||y2!=a.y2;
	}
};
node f[N][N][N][N];
int g[N][N][N][N]; 
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			cin>>c[i][j];
		}
	cin>>sx>>sy>>tx>>ty;
	dfs(tx,ty);
	reverse(ans.begin(),ans.end());
	for(auto i:ans)move(sx,sy,i);
	cout<<sx<<" "<<sy<<" "<<tx<<" "<<ty<<endl;
	cout<<ans<<endl;
	
	queue<node>q;
	q.push((node){sx,sy,tx,ty});
	while(!q.empty()){
		auto now=q.front();q.pop();
		int x=now.x1,y=now.y1,lx=now.x2,ly=now.y2;
		for(int k=0;k<4;k++){
			int nx=now.x1,ny=now.y1;
			move(nx,ny,k);
			if(!ok(lx+dx[k],ly+dy[k])){
				if(f[nx][ny][lx][ly]!=(node){0,0,0,0}){
					f[nx][ny][lx][ly]=(node){x,y,lx,ly};
					g[nx][ny][lx][ly]=k;
					q.push((node){nx,ny,lx,ly});
				}
			}
			if(ok(lx-dx[k],ly-dy[k])){
				if(f[nx][ny][lx-dx[k]][ly-dy[k]]!=(node){0,0,0,0}){
					f[nx][ny][lx-dx[k]][ly-dy[k]]=(node){x,y,lx,ly};
					g[nx][ny][lx-dx[k]][ly-dy[k]]=k;
					q.push((node){nx,ny,lx-dx[k],ly-dy[k]});
				}
			}
		}
	}
	cout<<"OK"; 
	int x1=0,x2=0,y1=0,y2=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			if(ok(i,j)&&f[i][j][i][j]!=(node){0,0,0,0}){
				x1=i,y1=j,x2=i,y2=j;mid="";
			}
			for(int k=0;k<4;k++){
				if(ok(i,j)&&ok(i+dx[k],j+dy[k])&&f[i][j][i+dx[k]][j+dy[k]]!=(node){0,0,0,0}){
					x1=i,y1=j,x2=i+dx[k],y2=j+dy[j];
					mid=dir[k];
				} 
			}
		}
	cout<<"OK";
	while(!(x1==sx&&y1==sy&&x2==tx&&y2==ty)){
		ans2+=g[x1][y1][x2][y2];
		auto tmp=f[x1][y1][x2][y2];
		x1=tmp.x1;y1=tmp.y1;x2=tmp.x2;y2=tmp.y2;
	}
	reverse(ans2.begin(),ans2.end());
	ans+=ans2;
	ans2=ans;
	reverse(ans2.begin(),ans2.end());
	ans+=mid+ans2;
	cout<<ans;aa
	return 0;
}

详细

answer.code: In function ‘int main()’:
answer.code:112:19: error: ‘aa’ was not declared in this scope
  112 |         cout<<ans;aa
      |                   ^~