Submission #19005

#TimeUsernameProblemLanguageResultExecution timeMemory
19005kriii로봇 (kriii4_F)C++14
4 / 100
257 ms524288 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...