Submission #1293429

#TimeUsernameProblemLanguageResultExecution timeMemory
1293429ducdevCandies (JOI18_candies)C++17
8 / 100
131 ms32956 KiB
// Author: 4uckd3v - Nguyen Cao Duc #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX_N = 2e5; const int MOD = 1e9 + 7; const ll INF = 1e18; int n; int a[MAX_N + 5]; namespace SUBTASK_1 { const int N = 2000; ll dp[N + 5][N + 5]; void Solve() { for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = -INF; for (int i = 0; i <= n; i++) dp[0][i] = 0; for (int i = 1; i <= (n + 1) >> 1; i++) { for (int j = i; j <= n; j++) { dp[i][j] = dp[i][j - 1]; if (j == 1) dp[i][j] = a[1]; if (j >= 2) dp[i][j] = max(dp[i][j], dp[i - 1][j - 2] + a[j]); }; cout << dp[i][n] << '\n'; }; }; }; // namespace SUBTASK_1 int main() { ios_base::sync_with_stdio(0); cin.tie(0); if (fopen("MAIN.INP", "r")) { freopen("MAIN.INP", "r", stdin); freopen("MAIN.OUT", "w", stdout); }; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; }; SUBTASK_1::Solve(); };

Compilation message (stderr)

candies.cpp: In function 'int main()':
candies.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen("MAIN.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen("MAIN.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...