Submission #47853

#TimeUsernameProblemLanguageResultExecution timeMemory
47853Just_Solve_The_ProblemCandies (JOI18_candies)C++11
8 / 100
5036 ms6456 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = (int)2e5 + 7; ll a[N], dp[2][N]; int n; main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } for (int j = 1; j <= (n + 1) / 2; j++) { memset(dp[j & 1], 0, sizeof dp[j & 1]); for (int i = j * 2 - 1; i <= n; i++) { dp[j & 1][i] = dp[j & 1][i - 1]; dp[j & 1][i] = max(dp[j & 1][i], dp[j & 1 ^ 1][i - 2] + a[i]); } printf("%lld\n", dp[j & 1][n]); } }

Compilation message (stderr)

candies.cpp:12:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
candies.cpp: In function 'int main()':
candies.cpp:21:45: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
       dp[j & 1][i] = max(dp[j & 1][i], dp[j & 1 ^ 1][i - 2] + a[i]);
                                           ~~^~~
candies.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
candies.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &a[i]);
     ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...