제출 #241052

#제출 시각아이디문제언어결과실행 시간메모리
241052Nightlight수열 (APIO14_sequence)C++14
54 / 100
1405 ms80552 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; bool 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] = i - 1; } } dnc(k, l, mid - 1, kl, bestid); dnc(k, mid + 1, r, bestid, kr); dp[skg][mid] = best; } 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...