답안 #47836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47836 2018-05-08T05:45:55 Z Just_Solve_The_Problem Candies (JOI18_candies) C++11
8 / 100
7 ms 704 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]);
  }
  for (int j = 1; 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 * 2 - 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

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:24: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]);
     ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 376 KB Output is correct
2 Correct 7 ms 488 KB Output is correct
3 Correct 7 ms 540 KB Output is correct
4 Correct 7 ms 540 KB Output is correct
5 Correct 7 ms 576 KB Output is correct
6 Correct 7 ms 704 KB Output is correct
7 Correct 7 ms 704 KB Output is correct
8 Correct 7 ms 704 KB Output is correct
9 Correct 7 ms 704 KB Output is correct
10 Correct 7 ms 704 KB Output is correct
11 Correct 7 ms 704 KB Output is correct
12 Correct 7 ms 704 KB Output is correct
13 Correct 7 ms 704 KB Output is correct
14 Correct 7 ms 704 KB Output is correct
15 Correct 7 ms 704 KB Output is correct
16 Correct 7 ms 704 KB Output is correct
17 Correct 7 ms 704 KB Output is correct
18 Correct 7 ms 704 KB Output is correct
19 Correct 7 ms 704 KB Output is correct
20 Correct 7 ms 704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 376 KB Output is correct
2 Correct 7 ms 488 KB Output is correct
3 Correct 7 ms 540 KB Output is correct
4 Correct 7 ms 540 KB Output is correct
5 Correct 7 ms 576 KB Output is correct
6 Correct 7 ms 704 KB Output is correct
7 Correct 7 ms 704 KB Output is correct
8 Correct 7 ms 704 KB Output is correct
9 Correct 7 ms 704 KB Output is correct
10 Correct 7 ms 704 KB Output is correct
11 Correct 7 ms 704 KB Output is correct
12 Correct 7 ms 704 KB Output is correct
13 Correct 7 ms 704 KB Output is correct
14 Correct 7 ms 704 KB Output is correct
15 Correct 7 ms 704 KB Output is correct
16 Correct 7 ms 704 KB Output is correct
17 Correct 7 ms 704 KB Output is correct
18 Correct 7 ms 704 KB Output is correct
19 Correct 7 ms 704 KB Output is correct
20 Correct 7 ms 704 KB Output is correct
21 Incorrect 1 ms 704 KB Output isn't correct
22 Halted 0 ms 0 KB -