제출 #37540

#제출 시각아이디문제언어결과실행 시간메모리
37540Talant수열 (APIO14_sequence)C++11
100 / 100
1213 ms82880 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long const int N = (int)1e5 + 7; const ll inf = (ll)1e18 + 7; ll dp[2][N]; ll pref[N]; int backtrack[201][N]; int n; ll calc (int l, int r) { return pref[l] * (pref[r] - pref[l]); } void div (int k, int l, int r, int optl, int optr) { if (l > r) return; int mid = (l + r) >> 1; dp[k & 1][mid] = 0; int opt = optl; for (int i = optl; i <= min(mid - 1, optr); i++) { ll cur = dp[k & 1 ^ 1][i] + calc(i, mid); if (cur >= dp[k & 1][mid]) { dp[k & 1][mid] = cur; opt = i; } } backtrack[k][mid] = opt; div(k, l, mid - 1, optl, opt); div(k, mid + 1, r, opt, optr); } main () { int k; scanf ("%d %d", &n, &k); for (int i = 1; i <= n; i++) { scanf ("%lld", pref + i); pref[i] += pref[i - 1]; } for (int i = 1; i <= k; i++) div(i, 1, n, 1, n - 1); printf ("%lld\n", dp[k & 1][n]); while (k > 0) { printf ("%d ", backtrack[k][n]); n = backtrack[k][n]; k--; } }

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

sequence.cpp: In function 'void div(int, int, int, int, int)':
sequence.cpp:26:23: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
         ll cur = dp[k & 1 ^ 1][i] + calc(i, mid);
                       ^
sequence.cpp: At global scope:
sequence.cpp:37:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
sequence.cpp: In function 'int main()':
sequence.cpp:38:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int k; scanf ("%d %d", &n, &k);
                                   ^
sequence.cpp:40:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%lld", pref + 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...