제출 #231978

#제출 시각아이디문제언어결과실행 시간메모리
231978Atalasion수열 (APIO14_sequence)C++14
100 / 100
1834 ms85432 KiB
//khodaya khodet komak kon #include <bits/stdc++.h> #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() #pragma GCC optimise ("ofast") #pragma GCC optimise("unroll-loops") //#define int long long using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; const int N = 100000 + 10; const ll MOD = 1000000000 + 7; const ll INF = 1000000000000000000; const ll LOG = 25; int n, k, a[N], opt[N][210]; ll dp[N][2], ps[N]; ll cost (int l, int r){ ll x = ps[r] - ps[l - 1]; return x * x; } int solve(int l, int r, int lq, int rq, int x, int f){ if (rq < lq) return 0; int md = (lq + rq) >> 1; for (int i = l; i < min(r + 1, md); i++){ if (dp[md][f] > dp[i][f ^ 1] + cost(i + 1, md)){ dp[md][f] = dp[i][f ^ 1] + cost(i + 1, md); opt[md][x] = i; } } //cout << opt[md][x] << '\n'; if (lq == rq) return 0; solve(l, opt[md][x], lq, md - 1, x,f); solve(opt[md][x], r, md + 1, rq, x,f); } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++){ cin >> a[i]; ps[i] = ps[i - 1] + a[i]; } if (k == 0) return cout << 0, 0; bool f = 0; for (int i = 1; i <= n; i++){ dp[i][1] = ps[i] * ps[i]; } for (int i = 2; i <= k + 1; i++){ for (int j = 0; j < N; j++) dp[j][f] = INF; solve(1, n, i, n, i, f); f ^= 1; } cout << (ps[n] * 1ll * ps[n] - dp[n][f ^ 1]) / 2<< '\n'; vector<int> ans; int Now = n; for (int i = k + 1; i >= 2; i--){ ans.pb(opt[Now][i]); Now = opt[Now][i]; } reverse(all(ans)); for (auto u:ans) cout << u << ' '; return 0; } /* 7 3 4 1 3 4 0 2 3 */

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

sequence.cpp:8:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
 #pragma GCC optimise ("ofast")
 
sequence.cpp:9:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
 #pragma GCC optimise("unroll-loops")
 
sequence.cpp: In function 'int solve(int, int, int, int, int, int)':
sequence.cpp:44:1: warning: control reaches end of non-void function [-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...