Submission #20075

#TimeUsernameProblemLanguageResultExecution timeMemory
20075gs13068로봇 (kriii4_F)C++98
4 / 100
40 ms524288 KiB
#include <cstdio> #include <map> const int p = 1000000007; using namespace std; int f(int x, int y) { return y & 1 ? (long long)f(x, y ^ 1)*x%p : y ? f((long long)x*x%p, y >> 1) : 1; } map<pair<int, pair<pair<int, int>, int> >, int> MM; int px[4] = { 1,0,-1,0 }; int py[4] = { 0,1,0,-1 }; int L, R, M; int g(int n, int x, int y, int z) { if (n == 0) return x*x + y*y; if (MM.find(make_pair(n, make_pair(make_pair(x, y), z))) != MM.end()) return MM[make_pair(n, make_pair(make_pair(x, y), z))]; int a = (long long)g(n - 1, x + px[z], y + py[z], z) * M % p; z = z + 1 & 3; int b = (long long)g(n - 1, x + px[z], y + py[z], z) * L % p; z = z + 2 & 3; int c = (long long)g(n - 1, x + px[z], y + py[z], z) * R % p; return MM[make_pair(n, make_pair(make_pair(x, y), z + 1 & 3))] = ((long long)a + b + c) * f(L + R + M, p - 2) % p; } int main() { int n; scanf("%d%d%d%d", &n, &L, &M, &R); printf("%d", g(n, 0, 0, 0)); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...