| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 163185 | TadijaSebez | Sandwich (JOI16_sandwich) | C++11 | 8061 ms | 6748 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N=405;
const int inf=N*N*2;
char mat[N][N];
int mv[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
int was[N][N];
int DFS(int x, int y, int dir)
{
if(mat[x][y]!='N' && mat[x][y]!='Z') return 0;
if(was[x][y]==2) return 0;
if(was[x][y]==1) return inf;
int ans=2,xr;
if(mat[x][y]=='N') xr=1;
else xr=3;
was[x][y]=1;
ans+=DFS(x+mv[dir][0],y+mv[dir][1],dir);
ans+=DFS(x+mv[dir^xr][0],y+mv[dir^xr][1],dir^xr);
was[x][y]=2;
return ans;
}
void cl(){ for(int i=0;i<N;i++) for(int j=0;j<N;j++) was[i][j]=0;}
int main()
{
int n,m;
scanf("%i %i",&n,&m);
for(int i=1;i<=n;i++) scanf("%s",mat[i]+1);
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
{
int ans=DFS(i,j,0);cl();
ans=min(ans,DFS(i,j,2));cl();
if(ans>=inf) printf("-1 ");
else printf("%i ",ans);
if(j==m) printf("\n");
}
return 0;
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
