# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
20060 | | xdoju | 로봇 (kriii4_F) | C++14 | | 1000 ms | 1720 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 <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;
}
}
return modprod(p, modprod(x, x) + modprod(y, y));
}
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();
ans = modprod(ans, modinv(modpow(l + m + r, n)));
printf("%d\n", ans);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |