제출 #552524

#제출 시각아이디문제언어결과실행 시간메모리
552524tht2005수열 (APIO14_sequence)C++17
39 / 100
2077 ms3488 KiB
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 100005; const int K = 202; int n, kk, s[N], trc[K][N]; LL f[N], g[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) { memcpy(g, f, sizeof(g)); memset(f, 0, sizeof(f)); for(int i = t + 1; i <= n; ++i) { for(int j = i - 1; j >= t; --j) { LL _ = g[j] + (LL)s[j] * (s[i] - s[j]); if(f[i] < _) { f[i] = _; trc[t][i] = j; } } } } printf("%lld\n", f[n]); for(int i = n; (i = trc[kk--][i]); ) { printf("%d ", i); } return 0; }

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

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