# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
19005 | | kriii | 로봇 (kriii4_F) | C++14 | | 257 ms | 524288 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 <stdio.h>
const long long mod = 1000000007;
long long pow(long long a, long long p)
{
a %= mod;
p = (p % (mod - 1) + mod - 1) % (mod - 1);
long long r = 1;
while (p){
if (p & 1) r = r * a % mod;
a = a * a % mod;
p /= 2;
}
return r;
}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int n,l,m,r;
long long sum;
void go(int a, int x, int y, int d, long long pr)
{
if (pr == 0) return;
if (a == n){
sum = (sum + (x * x + y * y) * pr % mod + mod) % mod;
}
else{
go(a+1,x+dx[d],y+dy[d],d,pr*m%mod);
go(a+1,x+dx[(d+1)%4],y+dy[(d+1)%4],(d+1)%4,pr*l%mod);
go(a+1,x+dx[(d+3)%4],y+dy[(d+3)%4],(d+3)%4,pr*r%mod);
}
}
int main()
{
while (~scanf ("%d %d %d %d",&n,&l,&m,&r)){
sum = 0;
go(0,0,0,0,1);
long long inv = pow(l+m+r,-1);
for (int i=0;i<n;i++){
sum = sum * inv % mod;
}
printf ("%lld\n",sum);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |