제출 #231963

#제출 시각아이디문제언어결과실행 시간메모리
231963Atalasion수열 (APIO14_sequence)C++14
0 / 100
80 ms131076 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") using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; const int N = 200000 + 10; const ll MOD = 1000000000 + 7; const ll INF = 1000000000000000000; const ll LOG = 25; int n, k, a[N], ps[N], opt[N][210]; ll dp[N][210]; 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){ if (rq < lq) return 0; int md = (lq + rq) >> 1; for (int i = l; i < min(r + 1, md); i++){ if (dp[md][x] > dp[i][x - 1] + cost(i + 1, md)){ dp[md][x] = dp[i][x - 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); solve(opt[md][x], r, md + 1, rq, x); } 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]; } for (int i = 0; i < N; i++) for (int j = 0; j < 210; j ++) dp[i][j] = INF; for (int i = 1; i <= n; i++){ dp[i][1] = ps[i] * ps[i]; } for (int i = 2; i <= k + 1; i++){ solve(1, n, 1, n, i); } cout << (ps[n] * 1ll * ps[n] - dp[n][k + 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)':
sequence.cpp:43: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...