Submission #20052

# Submission time Handle Problem Language Result Execution time Memory
20052 2016-02-25T08:54:42 Z cki86201 로봇 (kriii4_F) C++14
4 / 100
194 ms 524288 KB
#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 time Memory Grader output
1 Correct 0 ms 1720 KB Output is correct
2 Correct 0 ms 1720 KB Output is correct
3 Correct 0 ms 1720 KB Output is correct
4 Correct 7 ms 1720 KB Output is correct
5 Correct 0 ms 1720 KB Output is correct
6 Correct 0 ms 1720 KB Output is correct
7 Correct 7 ms 1720 KB Output is correct
8 Correct 0 ms 1720 KB Output is correct
9 Correct 0 ms 1720 KB Output is correct
10 Correct 22 ms 1720 KB Output is correct
11 Correct 0 ms 1720 KB Output is correct
12 Correct 0 ms 1720 KB Output is correct
13 Correct 7 ms 1720 KB Output is correct
14 Correct 0 ms 1720 KB Output is correct
15 Correct 0 ms 1720 KB Output is correct
16 Correct 7 ms 1720 KB Output is correct
17 Correct 0 ms 1720 KB Output is correct
18 Correct 0 ms 1720 KB Output is correct
19 Correct 0 ms 1720 KB Output is correct
20 Correct 0 ms 1720 KB Output is correct
21 Correct 0 ms 1720 KB Output is correct
22 Correct 0 ms 1720 KB Output is correct
23 Correct 0 ms 1720 KB Output is correct
24 Correct 0 ms 1720 KB Output is correct
25 Correct 3 ms 1720 KB Output is correct
26 Correct 0 ms 1720 KB Output is correct
27 Correct 0 ms 1720 KB Output is correct
28 Correct 0 ms 1720 KB Output is correct
29 Correct 65 ms 1720 KB Output is correct
30 Correct 194 ms 1720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 88 ms 524288 KB Memory limit exceeded
2 Halted 0 ms 0 KB -