Submission #222912

#TimeUsernameProblemLanguageResultExecution timeMemory
222912Bruteforceman수열 (APIO14_sequence)C++11
50 / 100
2081 ms5752 KiB
#include <bits/stdc++.h> using namespace std; int a[100010]; int n, k; long long pre[100010]; long long dp[202][100010], opt[202][100010]; const long long inf = 1e17; int main() { scanf("%d %d", &n, &k); k += 1; for(int i = 1; i <= n; i++) { scanf("%d", a + i); } for(int i = 1; i <= n; i++) { pre[i] = pre[i - 1] + a[i]; } long long sum = pre[n]; for(int j = 1; j <= n; j++) { dp[0][j] = -inf; } dp[0][0] = 0; for(int i = 1; i <= k; i++) { for(int j = 0; j <= n; j++) { dp[i][j] = -inf; for(int x = 0; x < j; x++) { long long cost = dp[i - 1][x] + (sum - pre[j] + pre[x]) * (pre[j] - pre[x]); if(cost > dp[i][j]) { dp[i][j] = cost; opt[i][j] = x; } } } } printf("%lld\n", dp[k][n] / 2); int cur = n; int cnt = k; while(cnt) { cur = opt[cnt--][cur]; if(cur) printf("%d ", cur); } puts(""); return 0; }

Compilation message (stderr)

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