답안 #19975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19975 2016-02-25T08:05:06 Z tonyjjw 로봇 (kriii4_F) C++14
4 / 100
95 ms 2824 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 2824 KB Output is correct
2 Correct 22 ms 2824 KB Output is correct
3 Correct 13 ms 2824 KB Output is correct
4 Correct 44 ms 2824 KB Output is correct
5 Correct 52 ms 2824 KB Output is correct
6 Correct 10 ms 2824 KB Output is correct
7 Correct 70 ms 2824 KB Output is correct
8 Correct 35 ms 2824 KB Output is correct
9 Correct 22 ms 2824 KB Output is correct
10 Correct 52 ms 2824 KB Output is correct
11 Correct 27 ms 2824 KB Output is correct
12 Correct 18 ms 2824 KB Output is correct
13 Correct 57 ms 2824 KB Output is correct
14 Correct 41 ms 2824 KB Output is correct
15 Correct 31 ms 2824 KB Output is correct
16 Correct 57 ms 2824 KB Output is correct
17 Correct 44 ms 2824 KB Output is correct
18 Correct 23 ms 2824 KB Output is correct
19 Correct 62 ms 2824 KB Output is correct
20 Correct 28 ms 2824 KB Output is correct
21 Correct 21 ms 2824 KB Output is correct
22 Correct 14 ms 2824 KB Output is correct
23 Correct 29 ms 2824 KB Output is correct
24 Correct 15 ms 2824 KB Output is correct
25 Correct 64 ms 2824 KB Output is correct
26 Correct 38 ms 2824 KB Output is correct
27 Correct 21 ms 2824 KB Output is correct
28 Correct 48 ms 2824 KB Output is correct
29 Correct 64 ms 2824 KB Output is correct
30 Correct 67 ms 2824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 95 ms 2820 KB SIGSEGV Segmentation fault
2 Halted 0 ms 0 KB -