| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1106900 | InvMOD | Split the sequence (APIO14_sequence) | C++14 | 1577 ms | 81316 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define gcd __gcd
#define sz(v) (int) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define dbg(x) "[" #x " = " << (x) << "]"
///#define int long long
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> bool ckmx(T& a, const T& b){if(a <= b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a >= b) return a = b, true; return false;}
const int N = 1e5+1;
const int K = 201;
const ll INF = 1e18;
struct Line{
ld a,b; int id;
Line(ld a = 0, ld b = 0, int id = 0): a(a), b(b), id(id) {}
ld intersect(Line& x){return (x.b - b)/(a - x.a);}
bool operator < (const Line& x) const{return a < x.a;}
};
struct CHT{
deque<pair<Line,ld>> dq;
void ins(Line x){
while(!dq.empty()){
if(dq.back().first.a != x.a){
if(dq.back().second >= dq.back().first.intersect(x)) dq.pop_back();
else{
break;
}
}
else{
if(dq.back().first.b <= x.b) dq.pop_back();
else{
return;
}
}
}
if(dq.empty()){
dq.push_back(make_pair(x, -INF));
}
else dq.push_back(make_pair(x, dq.back().first.intersect(x)));
return;
}
Line get(ll x){
while(dq.size() > 1 && dq[1].second <= x) dq.pop_front();
dq.front().second = -INF;
return dq.front().first;
}
void rest(){while(dq.size()) dq.pop_back();}
};
int n, k, a[N], trace[K][N];
ll dp[2][N];
void solve()
{
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> a[i];
a[i] += a[i-1];
}
CHT hull;
for(int i = 1; i <= k; i++){
for(int j = 1; j <= n; j++){
hull.ins(Line(a[j-1], dp[0][j-1] - 1ll*a[j-1] * a[j-1], j));
Line x = hull.get(a[j]);
ll aL = x.a, bL = x.b;
dp[1][j] = aL * (1ll*a[j]) + bL;
trace[i][j] = x.id;
}
swap(dp[0], dp[1]);
hull.rest();
}
cout << dp[0][n] <<"\n";
vector<int> path;
for(int cur_k = k, cur_pos = n; cur_k; cur_pos = trace[cur_k][cur_pos]-1, cur_k--){
path.push_back(trace[cur_k][cur_pos]-1);
}
reverse(all(path));
for(int i = 0; i < sz(path); i++) cout << path[i] <<" "; cout <<"\n";
return;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
}
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
