제출 #162531

#제출 시각아이디문제언어결과실행 시간메모리
162531combi1k1수열 (APIO14_sequence)C++14
49 / 100
2056 ms84264 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define X first #define Y second const int N = 1e5 + 1; typedef pair<ll,ll> ii; struct ConvexHull { int tot, ptr; ii line[N]; int name[N]; int bad(ii a,ii b,ii c) { return 1.0 * (c.Y - a.Y) / (a.X - c.X) <= 1.0 * (b.Y - a.Y) / (a.X - b.X); } int add(ll s,ll c,int i){ while (tot > 1) { if (bad(line[tot - 1],line[tot],ii(s,c))) { tot--; continue; } break; } ++tot; line[tot] = ii(s,c); name[tot] = i; } ll get(int i,int x) { return line[i].X * x + line[i].Y; } ii get(int x) { for(ptr = min(ptr,tot) ; ptr < tot && get(ptr,x) <= get(ptr + 1,x) ; ++ptr); return ii(get(ptr,x),name[ptr]); } } Combi; int a[N], c[N]; ll f[N]; int opt[N][205]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int k; cin >> k; for(int i = 1 ; i <= n ; ++i) cin >> a[i], a[i] += a[i - 1]; Combi.add(0,0,0); for(int i = 1 ; i <= k + 1 ; ++i) { for(int j = i ; j <= n ; ++j) { int t = Combi.get(2 * a[j]).Y; ll C = Combi.get(2 * a[j]).X; f[j] = 1ll * a[j] * a[j] - C; opt[j][i] = t; } Combi.tot = 0; Combi.ptr = 0; for(int j = i ; j <= n ; ++j) Combi.add(a[j], -f[j] - 1ll * a[j] * a[j],j); } cout << (1ll * a[n] * a[n] - f[n]) / 2 << "\n"; stack<int> res; for(int i = k + 1 ; i > 1 ; --i) res.push(n = opt[n][i]); while (res.size()) cout << res.top() << " ", res.pop(); } /* 7 3 4 1 3 4 0 2 3 */

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

sequence.cpp: In member function 'int ConvexHull::add(long long int, long long int, int)':
sequence.cpp:33:5: warning: no return statement in function returning non-void [-Wreturn-type]
     }
     ^
#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...