제출 #241058

#제출 시각아이디문제언어결과실행 시간메모리
241058Nightlight수열 (APIO14_sequence)C++14
100 / 100
1333 ms80760 KiB
#include <bits/stdc++.h> using namespace std; int N, K; long long pre[100001]; long long dp[2][100001]; int opt[201][100001]; long long cost(int l, int r) { return pre[l - 1] * (pre[r] - pre[l - 1]); } void dnc(int k, int l, int r, int kl, int kr) { if(l > r) return; long long best = -1e18, bestid = 0; int mid = (l + r) >> 1; int skg = k & 1; for(int i = kl; i <= mid && i <= kr; i++) { long long now = dp[!skg][i - 1] + cost(i, mid); if(now > best) { bestid = i; best = now; } } opt[k][mid] = bestid - 1; dp[skg][mid] = best; dnc(k, l, mid - 1, kl, bestid); dnc(k, mid + 1, r, bestid, kr); } int main() { scanf("%d %d", &N, &K); K++; for(int i = 1; i <= N; i++) { scanf("%lld", &pre[i]); pre[i] += pre[i - 1]; } for(int i = 2; i <= K; i++) { dnc(i, i, N, i, N); } printf("%lld\n", dp[K & 1][N]); int now = N; vector<int> ans; for(int i = K; i > 1; i--) { now = opt[i][now]; ans.push_back(now); } for(int i = ans.size() - 1; i >= 0; i--) printf("%d ", ans[i]); puts(""); cin >> N; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:32: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:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &pre[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...