제출 #29705

#제출 시각아이디문제언어결과실행 시간메모리
29705sampriti수열 (APIO14_sequence)C++14
50 / 100
2000 ms25964 KiB
#include <cstdio>
#include <algorithm>
#include <climits>

using namespace std;

int N, K;
int A[100001];
long long P[100001];
long long dp[10002][202];
int nxt[10002][202];

int main() {
  scanf("%d %d", &N, &K);
  for(int i = 1; i <= N; i++) scanf("%d", &A[i]);
  for(int i = 1; i <= N; i++) P[i] = P[i - 1] + A[i];

  dp[N + 1][1] = LLONG_MIN/2;
  for(int j = 2; j <= K + 1; j++) {
    dp[N + 1][j] = LLONG_MIN/2;
    for(int i = N; i >= 1; i--) {
      dp[i][j] = LLONG_MIN/2;
      for(int k = i; k <= N; k++) {
        long long curr = (P[k] - P[i - 1]) * (P[N] - P[k]) + dp[k + 1][j - 1];
        if(curr > dp[i][j]) {
          dp[i][j] = curr;
          nxt[i][j] = k;
        }
      }
    }
  }

  printf("%lld\n", dp[1][K + 1]);

  int i = 1, j = K + 1;
  while(j > 1) {
    printf("%d ", nxt[i][j]);
    i = nxt[i][j] + 1;
    j--;
  }
  printf("\n");
}

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'int main()':
sequence.cpp:14:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &N, &K);
                         ^
sequence.cpp:15:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i = 1; i <= N; i++) scanf("%d", &A[i]);
                                                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...