Submission #47832

# Submission time Handle Problem Language Result Execution time Memory
47832 2018-05-08T05:34:05 Z Just_Solve_The_Problem Candies (JOI18_candies) C++11
0 / 100
10 ms 376 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int N = (int)1e5 + 7;
const int smallN = (int)2e3 + 7;

ll a[smallN], dp[2][smallN];
int n;

main() {
  scanf("%d", &n);
  if (n > 2000) return 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  ll mx = 0;
  for (int i = 1; i <= n; i++) {
    mx = max(mx, a[i]);
    dp[1][i] = mx;
  }
//  puts("***");
  cout << mx << endl;
  for (int j = 2; j <= (n + 1) / 2; j++) {
    memset(dp[j & 1], 0, sizeof dp[j & 1]);
    for (int i = j; i <= n; i++) {
      dp[j & 1][i] = dp[j & 1][i - 1];
      if (i > j)
        dp[j & 1][i] = max(dp[j & 1][i], dp[j & 1 ^ 1][i - 2] + a[i]);
    }
    cout << dp[j & 1][n] << endl;
  }
}

Compilation message

candies.cpp:13:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
candies.cpp: In function 'int main()':
candies.cpp:31:47: 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:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
candies.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &a[i]);
     ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -