Submission #629325

#TimeUsernameProblemLanguageResultExecution timeMemory
629325MohamedFaresNebiliHoliday (IOI14_holiday)C++14
0 / 100
10 ms2084 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define ff first #define ss second #define pb push_back #define all(x) (x).begin(), (x).end() #define lb lower_bound int DP[25][55][2], dp[25][55][2]; ll solve(int i, int K, int add, int N, int S, int D, int C[]) { if(i < 0 || i == N || K <= 0) return 0; if(DP[i][K][add] != -1) return DP[i][K][add]; if(add == 0) { int A = solve(i - 1, K - 1, add, N, S, D, C); int B = C[i] + solve(i - 1, K - 2, add, N, S, D, C); int U = solve(S + 1, K - (S - i), 1 - add, N, S, D, C); int V = C[i] + solve(S + 1, K - (S - i) - 1, 1 - add, N, S, D, C); return DP[i][K][add] = max({A, B, U, V}); } if(add == 1) { int A = solve(i + 1, K - 1, add, N, S, D, C); int B = C[i] + solve(i + 1, K - 2, add, N, S, D, C); return DP[i][K][add] = max({A, B}); } return 0; } ll Solve(int i, int K, int add, int N, int S, int D, int C[]) { if(i < 0 || i == N || K <= 0) return 0; if(dp[i][K][add] != -1) return DP[i][K][add]; if(add == 0) { int A = Solve(i + 1, K - 1, add, N, S, D, C); int B = C[i] + Solve(i + 1, K - 2, add, N, S, D, C); int U = Solve(S - 1, K - (i - S), 1 - add, N, S, D, C); int V = C[i] + Solve(S - 1, K - (S - i + 1), 1 - add, N, S, D, C); return dp[i][K][add] = max({A, B, U, V}); } if(add == 1) { int A = Solve(i - 1, K - 1, add, N, S, D, C); int B = C[i] + Solve(i - 1, K - 2, add, N, S, D, C); return dp[i][K][add] = max({A, B}); } return 0; } ll findMaxAttraction(int N, int start, int D, int attraction[]) { memset(DP, -1, sizeof DP); memset(dp, -1, sizeof dp); ll A = solve(start, D, 0, N, start, D, attraction); ll B = Solve(start, D, 0, N, start, D, attraction); return max(A, B); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...