玄学问题
查看原帖
玄学问题
1045028
xhz123456789楼主2024/5/16 22:26

以下代码WA11,但是下载数据后在本地和在线ide都输出正确答案,有没有大佬知道是咋回事

#include<bits/stdc++.h>
using namespace std;
struct X_Y{
    int x,y;
    inline friend X_Y operator+(X_Y const a,X_Y const b){return {a.x+b.x,a.y+b.y};}
    inline X_Y operator+=(X_Y const b){return {x+=b.x,y+=b.y};}
    inline friend X_Y operator-(X_Y const a){return {-a.x,-a.y};}
    inline friend bool operator==(X_Y a,X_Y b){return a.x==b.x&&a.y==b.y;}
    template<class T> inline auto& get(T const &t){return t[x][y];}
};
int n,m,t;
X_Y p1,p2;
char grass[115][115];
long long  dfs(X_Y now,int r){
    if(r==0) return (long long)(now==p2);
    long long  ans=0;
    for(X_Y i:{now+X_Y{1,0},now+X_Y{0,1},now+X_Y{-1,0},now+X_Y{0,-1}}) 
    if(((abs(i.x-p2.x)+abs(i.y-p2.y))<=r)&&(i.get(grass)=='.')) ans+=dfs(i,r-1);
    return ans;
}
int main(){
    cin>>n>>m>>t;
    for(int i=0;i<=n;i++)cin.getline(grass[i]+1,m+1);
    cin>>p1.x>>p1.y>>p2.x>>p2.y;
    long long ans=dfs(p1,t);
    cout<<ans;
    return 0;
}
2024/5/16 22:26
加载中...