Submission #20052

#TimeUsernameProblemLanguageResultExecution timeMemory
20052cki86201로봇 (kriii4_F)C++14
4 / 100
194 ms524288 KiB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()

const ll MOD = 1e9 + 7;

ll pw(ll x, ll y){
	ll res = 1;
	while(y){
		if(y & 1)res = res * x % MOD;
		x = x * x % MOD;
		y >>= 1;
	}
	return res;
}

int xx[4] = {1, 0, -1, 0};
int yy[4] = {0, 1, 0, -1};

int n, l, r, m;
ll cnt = 0;

void dfs(int dep, int x, int y, ll now, int dir){
	if(dep == 0){
		cnt = (cnt + (x*x + y*y) * now) % MOD;
		return;
	}
	int ndir;
	ndir = (dir + 1) % 4;
	dfs(dep-1, x + xx[ndir], y + yy[ndir], now * l % MOD, ndir);
	ndir = (dir + 3) % 4;
	dfs(dep-1, x + xx[ndir], y + yy[ndir], now * r % MOD, ndir);
	ndir = dir;
	dfs(dep-1, x + xx[ndir], y + yy[ndir], now * m % MOD, ndir);
}

int main(){
	scanf("%d%d%d%d", &n, &l, &m, &r);
	dfs(n, 0, 0, 1, 0);
	cnt = cnt * pw(pw(l+r+m, n), MOD-2) % MOD;
	printf("%lld", cnt);
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...