Submission #20046

#TimeUsernameProblemLanguageResultExecution timeMemory
20046xdoju로봇 (kriii4_F)C++14
0 / 100
1000 ms1720 KiB
#include <iostream>
#include <cstdio>

using namespace std;
typedef long long ll;

const int MOD = 1000000007ll;

inline int modpow(int r, int n) {
	int ret = 1;
	while (n > 0) {
		if (n % 2 > 0) {
			ret = ((long long)ret * r) % MOD;
		}
		r = ((long long)r * r) % MOD;
		n /= 2;
	}
	return ret;
}

inline int modinv(int n) {
	return modpow(n, MOD - 2);
}

inline int modprod(int a, int b) {
	a = a % MOD;
	b = b % MOD;
	return ((long long)a * b) % MOD;
}

inline int modprod(int a, int b, int c) {
	c = c % MOD;
	return (modprod(a, b) * (long long)c) % MOD;
}

inline int moddiv(int a, int b) {
	return ((long long)a * modinv(b)) % MOD;
}

int n, l, m, r;
int ans = 0;
int a[22];

int brute2() {
	int p = 1, x = 0, y = 0, dir = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] == 0)
			p = modprod(p, l);
		else if (a[i] == 1)
			p = modprod(p, m);
		else
			p = modprod(p, r);

		if (dir == 0) {
			if (a[i] == 0) y = y + 1, dir = 1;
			else if (a[i] == 1) x = x + 1, dir = 0;
			else y = y - 1, dir = 3;
		}
		else if (dir == 1) {
			if (a[i] == 0) x = x - 1, dir = 2;
			else if (a[i] == 1) y = y + 1, dir = 1;
			else x = x + 1, dir = 0;
		}
		else if (dir == 2) {
			if (a[i] == 0) y = y - 1, dir = 3;
			else if (a[i] == 1) x = x - 1, dir = 2;
			else y = y + 1, dir = 1;
		}
		else {
			if (a[i] == 0) x = x + 1, dir = 0;
			else if (a[i] == 1) y = y - 1, dir = 3;
			else x = x - 1, dir = 2;
		}
	}

	int inv = modinv(modpow(l + m + r, n));
	return modprod(modprod(p, modprod(x, x) + modprod(y, y)), inv);
}

void brute(int process = 0) {
	if (process == n) {
		ans += brute2();
		ans %= MOD;
		return;
	}

	a[process] = 0;
	brute(process + 1);
	a[process] = 1;
	brute(process + 1);
	a[process] = 2;
	brute(process + 1);
}

int main() {
	cin >> n >> l >> m >> r;

	brute();
	printf("%d\n", ans);

	return 0;
}	
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...