QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#394482#7751. Palindrome PathJelly_prxCompile Error//C++141.9kb2024-04-20 15:12:072024-04-20 15:12:09

Judging History

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

  • [2024-04-20 15:12:09]
  • 评测
  • [2024-04-20 15:12:07]
  • 提交

answer

#include<iostream>
#include<cstdio>
using namespace std;
const int N=35;
int n,m,tot,can;
int sx,sy,tx,ty;
bool vis[N][N],mp[N][N];
int f[N][N][4],g[N][N][4][2];
int dx[4]={-1,1,0,0},
	dy[4]={0,0,-1,1};
char t[4]={'U','D','L','R'},outp[N*N*N<<4];int cnt;
char s[N];
int stk[N*N],top;
int spc[N*N],len;
int op[N*N*N],k;
void dfs(int x,int y,int dir){
	if(x==tx&&y==ty) len=top,memcpy(spc,stk,sizeof stk);
	vis[x][y]=true,can++;
	for(int d=0;d<4;d++){
		int xx=x+dx[d],yy=y+dy[d];
		if(!mp[xx][yy]||vis[xx][yy]) continue;
		stk[++top]=d,op[++k]=d,dfs(xx,yy,d);
	} 
	if(dir<4) op[++k]=dir^1;
	top--;
}
void walk(int *a,int len){
	for(int i=1;i<=len;i++){
		int to=a[i];
		for(int j=1;j<=g[sx][sy][to][1];j++) printf("%c",outp[++cnt]=t[to^1]);
		for(int j=1;j<=g[sx][sy][to][0];j++) printf("%c",outp[++cnt]=t[to]);
		sx=sx+dx[to],sy=sy+dy[to];
	}
}
void solve(int x,int y,int d){
	if(f[x][y][d]<2) return ;
	if(f[x][y][d^1]>=f[tx][ty][d]){
		g[x][y][d][1]=f[tx][ty][d]-1;
		g[x][y][d][0]=f[tx][ty][d];
	}
	else g[x][y][d][0]=g[x][y][d][1]=f[x][y][d^1]; 
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		for(int j=1;j<=m;j++)
		  mp[i][j]=s[j]-'0',tot+=mp[i][j];
	}
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++){
	  	if(!mp[i][j]) continue;
	  	f[i][j][0]=f[i-1][j][0]+1;
		f[i][j][2]=f[i][j-1][2]+1; 
	  }
	for(int i=n;i>=1;i--)
	  for(int j=m;j>=1;j--){
	  	if(!mp[i][j]) continue;
	  	f[i][j][1]=f[i+1][j][1]+1;
	  	f[i][j][3]=f[i][j+1][3]+1; 
	  }
	scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
	dfs(sx,sy,4);
	if(can<tot) return 0*printf("-1");
	
	for(int i=1;i<=k;i++) printf("%c",t[op[i]]);
	for(int i=1;i<=len;i++) printf("%c",t[spc[i]]);
	putchar('\n');
	
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	    if(mp[i][j])
	      for(int d=0;d<4;d++)
	        solve(i,j,d);
	walk(op,k),walk(spc,len);
	while(cnt) printf("%c",outp[cnt--]);
}

詳細信息

answer.code: In function ‘void dfs(int, int, int)’:
answer.code:17:34: error: ‘memcpy’ was not declared in this scope
   17 |         if(x==tx&&y==ty) len=top,memcpy(spc,stk,sizeof stk);
      |                                  ^~~~~~
answer.code:3:1: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
    2 | #include<cstdio>
  +++ |+#include <cstring>
    3 | using namespace std;
answer.code: In function ‘int main()’:
answer.code:44:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |         scanf("%d%d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~
answer.code:46:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |                 scanf("%s",s+1);
      |                 ~~~~~^~~~~~~~~~
answer.code:62:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |         scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~