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 <algorithm>
#include <assert.h>
#include <complex>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <limits.h>
#include <locale.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#pragma warning(disable:4996)
using namespace std;
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <ldb, ldb> pdd;
int IT_MAX = 131072;
const ll MOD = 1000000007;
const int INF = 1034567891;
const ll LL_INF = 2234567890123456789ll;
const db PI = 3.141592653589793238;
const ldb ERR = 1E-10;
ll mul_inv(ll a, ll b)
{
ll b0 = b, t, q;
ll x0 = 0, x1 = 1;
if (b == 1) return 1;
while (a > 1) {
q = a / b;
t = b, b = a % b, a = t;
t = x0, x0 = x1 - q * x0, x1 = t;
}
if (x1 < 0) x1 += b0;
return x1;
}
ll dp[21][41][41][4];
int P[4][2] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };
int main() {
int N, L, M, R, i, j, k, l;
scanf("%d %d %d %d", &N, &L, &M, &R);
dp[0][20][20][0] = 1;
for (i = 0; i < N; i++) {
for (j = 1; j <= 39; j++) {
for (k = 1; k <= 39; k++) {
for (l = 0; l < 4; l++) {
int d = l;
int x = j + P[d][0];
int y = k + P[d][1];
dp[i + 1][x][y][d] += dp[i][j][k][l] * M % MOD * mul_inv(L + M + R, MOD);
dp[i + 1][x][y][d] %= MOD;
d = (l + 1) % 4;
x = j + P[d][0];
y = k + P[d][1];
dp[i + 1][x][y][d] += dp[i][j][k][l] * L % MOD * mul_inv(L + M + R, MOD);
dp[i + 1][x][y][d] %= MOD;
d = (l + 3) % 4;
x = j + P[d][0];
y = k + P[d][1];
dp[i + 1][x][y][d] += dp[i][j][k][l] * R % MOD * mul_inv(L + M + R, MOD);
dp[i + 1][x][y][d] %= MOD;
}
}
}
}
ll ans = 0;
for (i = 0; i <= 40; i++) for (j = 0; j <= 40; j++) for (k = 0; k < 4; k++) ans = (ans + ((i - 20)*(i - 20) + (j - 20)*(j - 20))*dp[N][i][j][k]) % MOD;
printf("%lld\n", ans);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |