제출 #552516

#제출 시각아이디문제언어결과실행 시간메모리
552516tht2005수열 (APIO14_sequence)C++17
0 / 100
2089 ms79316 KiB
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 100001; const int K = 201; int n, kk, s[N], f[K][N]; int main() { scanf("%d %d", &n, &kk); for(int i = 1; i <= n; ++i) { int a; scanf("%d", &a); s[i] = s[i - 1] + a; } memset(f, 0, sizeof(f)); for(int t = 1; t <= kk; ++t) { for(int i = t + 1; i <= n; ++i) { for(int j = i - 1; j >= t; --j) { f[t][i] = max(f[t][i], f[t - 1][j] + s[j] * (s[i] - s[j])); } } } printf("%d\n", f[kk][n]); for(int i, j = n; kk--; ) { for(i = j; i--; ) { if(f[kk + 1][j] == f[kk][i] + s[i] * (s[j] - s[i])) { printf("%d ", i); j = i; break; } } } return 0; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d %d", &n, &kk);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
sequence.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%d", &a);
      |         ~~~~~^~~~~~~~~~
#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...