제출 #20044

#제출 시각아이디문제언어결과실행 시간메모리
20044noeffserv괄호 (kriii4_R)C++98
0 / 100
16 ms25160 KiB
#include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <functional> #include <cstring> #include <string> #include <map> #include <set> #include <iostream> #define ENP printf("**Entry Point**\n") #define A first #define B second #define MP make_pair using namespace std; typedef long long ll; typedef vector <double> vec_d; typedef vector <vec_d> vvec_d; typedef vector <int> vec_i; typedef vector <vec_i> vvec_i; typedef pair <int, int> pair_i; typedef pair < pair_i, pair_i > pp_i; const int INF = 0x60000000; const int MINF = -1000000000; const ll mod = 1000000007; const int cons = 50000001; ll dp2[1000001]; ll dp[1000001][2]; int main() { int n; ll k; scanf("%d%lld", &n, &k); dp2[0] = 1; for (int i = 0; i <= n; i++) { dp2[i + 1] = (k*(((4 * ((ll)i) + 2)*dp2[i] / (((ll)i) + 2))%mod))%mod; } dp[0][0] = 1; dp[1][1] = k; for (int i = 2; i <= n; i++) { if (i % 2 == 0) { dp[i][0] = dp2[i/2]; dp[i][1] = (dp[i - 1][0] * k + dp[i - 1][1] * k + dp[i - 2][1] * k) % mod; } else { dp[i][1] = (dp[i - 1][0] * k + dp[i - 1][1] * k + dp[i - 2][1] * k) % mod; if ((i / 2) % 2 == 0) { dp[i][1] = (dp[i][1] + dp[i / 2][1] * k) % mod; } } } printf("%lld\n", (dp[n][0] + dp[n][1])%mod); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...