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>
//#include "arithmetics.h";
using namespace std;
const int MOD=1e9+7, MAXN=100;
int m, n, s, e;
int memo[MAXN][MAXN][3*MAXN];
int adj[8][2]={{1,0},{0,1},{-1,0},{0,-1},{1,-1},{-1,1},{1,1},{-1,-1}};
int dp(int x, int y, int moves)
{
if (x>=m || x<0 || y>=n || y<0)
return 0;
if (x==0 && y==s)
return 1;
if (moves==0)
return 0;
if (memo[x][y][moves]!=-1)
return memo[x][y][moves];
int total=0;
for (int i=0; i<8; i++)
total=(total+dp(x+adj[i][0], y+adj[i][1], moves-1))%MOD;
return memo[x][y][moves]=total;
}
int main()
{
//ios_base::sync_with_stdio(0);
//cin.tie(0);
int q;
char type;
cin >> m >> n >> q;
while (q--)
{
cin >> type >> s >> e;
s=s-1;
e=e-1;
if (s>e)
swap(s, e);
int w=s-e;
int h=m-1-w;
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
for (int k=0; k<3*n; k++)
memo[i][j][k]=-1;
cout << w+h << " " << dp(m-1, e, w+h) << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |