제출 #586588

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
5865882022-06-30 12:07:58Alan수열 (APIO14_sequence)C++17
0 / 100
24 ms4692 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll dp[2][100005], ps[100005];
int p[205][100005];
struct line {
ll idx, m, c;
ll cal (ll x) {return m*x + c;}
ld sectx (line l) {return (ld) (l.c-c) / (m-l.m);}
};
int main () {
int n, k, a;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a, ps[i] = ps[i-1] + a;
deque<line> d;
for (int j = 1; j <= k; j++) {
d.push_back({0, 0, 0});
for (int i = 1; i <= n; i++) {
while ((int) d.size() >= 2 && d.end()[-2].cal(ps[i]) >= d.back().cal(ps[i])) d.pop_back();
if (!d.empty()) dp[j&1][i] = d.back().cal(ps[i]) + ps[i]*ps[n] - ps[i]*ps[i];
p[j][i] = d.back().idx;
line now = {i, ps[i], dp[~j&1][i] - ps[i]*ps[n]};
while ((int) d.size() >= 2 && d[0].sectx(d[1]) <= now.sectx(d[0])) d.pop_front();
d.push_front(now);
}
d.clear();
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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

sequence.cpp: In function 'int main()':
sequence.cpp:34:24: warning: narrowing conversion of '((iter - ((ll*)(& dp[(k & 1)]))) <unknown operator> 8)' from 'long int' to 'int' [-Wnarrowing]
   34 |  vector<int> path {iter-dp[k&1]};
      |                    ~~~~^~~~~~~~
sequence.cpp:34:24: warning: narrowing conversion of '((iter - ((ll*)(& dp[(k & 1)]))) <unknown operator> 8)' from 'long int' to 'int' [-Wnarrowing]
#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...