Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
57454 | luogu775213 | J4 | C++ | 运行出错 | 0 | 88 MS | 7456 KB | 1452 | 2022-10-04 11:25:38 |
#include<cstdio> #include<cstring> #include<cmath> #define MAXN 1002 #define inf 0x7fffffffffff #define B 1000000000000000 #define C 2000000000000021 unsigned long long sum; int n,m,v[MAXN][MAXN]; unsigned long long ans,all; char c; short dir[MAXN][MAXN]; bool vis[MAXN][MAXN],b[MAXN][MAXN]; int x[]={-1,1,0,0}, y[]={0,0,-1,1}; unsigned long long dfs(int xa,int ya,bool flag,unsigned long long sum,unsigned long long max) { if((!xa||!ya||xa==n+1||ya==m+1)||(vis[xa][ya]&&(!v[xa][ya]||(v[xa][ya]>0&&b[xa][ya]^flag)||(v[xa][ya]<0&&!(b[xa][ya]^flag))))) return max; vis[xa][ya]=1; if(flag) { if(b[xa][ya]) sum+=v[xa][ya]; else sum-=v[xa][ya]; } else { if(b[xa][ya]) sum-=v[xa][ya]; else sum+=v[xa][ya]; b[xa][ya]^=1; } max=max>sum?max:sum; return dfs(xa+x[dir[xa][ya]],ya+y[dir[xa][ya]],flag^1,sum,max); } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { do c=getchar(); while(c!='<'&&c!='>'&&c!='^'&&c!='v'); if(c=='^') dir[i][j]=1; if(c=='v') dir[i][j]=2; if(c=='<') dir[i][j]=3; if(c=='>') dir[i][j]=4; } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&v[i][j]); all=0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { memset(vis,0,sizeof(vis)); memset(b,0,sizeof(b)); ans=dfs(i,j,0,0,-inf); all+=(ans+B)*(unsigned long long)(pow(C,(i-1)*m+j-1)); } printf("%llu\n",all); return 0; }