제출 #365076

#제출 시각아이디문제언어결과실행 시간메모리
365076saleh수열 (APIO14_sequence)C++17
0 / 100
2073 ms2520 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int MAXN = 100 * 1000 + 2, MAXK = 200 + 2; int n, k, dp[2 + 2][MAXN], ps[MAXN], chi, lvl; int32_t par[MAXK][MAXN]; void cal(int32_t l = chi, int32_t r = n + 1, int32_t ll = chi, int32_t rr = n) { int32_t mid = ((l + r) >> 1), md = -1; for (int i = ll; i < mid && i < r; i++) { if (dp[1 - lvl][i] + ps[i] * (ps[mid] - ps[i]) > dp[lvl][mid]) { dp[lvl][mid] = dp[1 - lvl][i] + ps[i] * (ps[mid] - ps[i]); md = i; } } par[chi][mid] = md; if (l < mid) cal(l, mid, ll, md); if (mid + 1 < r) cal(mid + 1, r, md, rr); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> n >> k; int32_t a; for (int i = 0; i < n; i++) { scanf("%d", &a); ps[i + 1] = ps[i] + a; } for (int i = 1; i <= k; i++) { chi = i; lvl = i & 1; memset(dp[lvl], -1, sizeof dp[lvl]); cal(); } printf("%lld\n", dp[k & 1][n]); while (k > 0) { printf("%d ", par[k][n]); n = par[k][n]; k--; } return 0; }

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

sequence.cpp: In function 'int32_t main()':
sequence.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   49 |   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...