Submission #19655

#TimeUsernameProblemLanguageResultExecution timeMemory
19655yukariko괄호 (kriii4_R)C++14
0 / 100
4 ms19704 KiB
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int N, M; int cache[1000001]; int solve(int pos) { if(pos > N) return 0; if(pos == N) return 1; int& ans = cache[pos]; if(ans != -1) return ans; ans = (1LL * solve(pos + 1) * M) % MOD; ans = (ans + 1LL * solve(pos + 2) * M) % MOD; return ans; } int main() { memset(cache, -1, sizeof(cache)); scanf("%d%d", &N, &M); printf("%d", solve(0)); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...