제출 #801461

#제출 시각아이디문제언어결과실행 시간메모리
801461beaboss수열 (APIO14_sequence)C++14
0 / 100
89 ms131072 KiB
// Source: https://docs.google.com/document/d/1ryBjActxSlAAeTMRNUmJzWOGQ21ZuS32mQYTD8rHXzE/edit #include "bits/stdc++.h" using namespace std; #define s second #define f first #define pb push_back typedef long long ll; typedef pair<ll, ll> pii; typedef vector<pii> vpii; typedef vector<ll> vi; #define FOR(i, a, b) for (ll i = (a); i<b; i++) struct line { ll m, b; ll eval(ll x) {return m * x + b; } ll isectX(line l) {return (long double) (l.b - b) / (m - l.m); } }; vector<deque<line> > lines(300); vector<deque<ll > > indexes(300); vi lls(1000000); void add(ll i, line l, ll ind) { while (lines[i].size() > 1 && ((l.m == lines[i].back().m) || l.isectX((lines[i].back())) <= l.isectX((lines[i][lines[i].size() - 2])))) { lines[i].pop_back(); indexes[i].pop_back(); } lines[i].push_back(l); indexes[i].push_back(ind); } pii query(ll i, ll x) { while (lines[i].size() > 1 && lines[i][0].isectX(lines[i][1]) < x) { lines[i].pop_front(); indexes[i].pop_front(); } return {lines[i][0].eval(x), indexes[i][0]}; } ll prv[100005][201]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); iota(lls.begin(), lls.end(), 0); ll n, k; cin >> n >> k; vi vals(n + 1); vi pref(n + 1); FOR(i, 1, n + 1) { cin >> vals[i]; pref[i] = vals[i] + pref[i-1]; } add(0, {0, 0}, 0); ll ans = 0; ll best; FOR(i, 1, n + 1) { for (ll j = k; j>= 1; j--) { pii q = query(j-1, pref[i]); ll cur = pref[i] * pref[n] - pref[i] * pref[i] + q.f; prv[i][j] = q.s; add(j, {pref[i], cur - pref[i] * pref[n]}, i); if (cur > ans) best = i; ans = max(ans, cur); } } cout << ans << endl; ll cur_n = best; for (ll cur_k = k; cur_k > 0; cur_k--) { cout << cur_n << ' '; cur_n = prv[cur_n][cur_k]; } cout << endl; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:96:9: warning: 'best' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |   cur_n = prv[cur_n][cur_k];
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~
#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...