제출 #162180

#제출 시각아이디문제언어결과실행 시간메모리
162180kostia244수열 (APIO14_sequence)C++14
71 / 100
2077 ms111124 KiB
//#pragma comment(linker, "/stack:200000000") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #include<bits/extc++.h> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back using namespace std; using namespace __gnu_pbds; using ll = long long; using vi = vector<ll>; using vvi = vector<vector<ll>>; const ll mod = 998244353; using oset = tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); using vec = complex<ll>; using ld = long double; using vld = complex<ld>; ll dot(vec a, vec b) { return (conj(a) * b).real(); } ll cross(vec a, vec b) { return (conj(a) * b).imag(); } struct cht { vector<vec> hull; vector<ll> id; void clear() { hull.clear(); id.clear(); } bool nok(ld x, ld y, ld x1, ld y1, ld x2, ld y2) { vld a(x1 - x, y1 - y); vld b(x2 - x1, y2 - y1); return (conj(a) * b).imag() > -(1e-3); } bool rem() { int n = hull.size(); if (n < 3) return 0; return nok(hull[n - 3].real(), hull[n - 3].imag(), hull[n - 2].real(), hull[n - 2].imag(), hull[n - 1].real(), hull[n - 1].imag()); } void add(vec x, int i) { hull.pb(x); id.pb(i); while (rem()) { swap(hull.back(), hull[hull.size() - 2]), hull.pop_back(); swap(id.back(), id[id.size() - 2]), id.pop_back(); } } ll get(vec x, ll &v) { ll l = 0, r = (int)hull.size() - 1, a, b; while (r - l > 3) { a = l + (r - l) / 3; b = r - (r - l) / 3; if (dot(x, hull[a]) < dot(x, hull[b])) l = a; else r = b; } ll ans = 0; vec z; while (l <= r) { ans = max(ans, dot(x, hull[l])); if(ans==dot(x, hull[l])) z=hull[l], v = id[l]; l++; } return ans; } }; const int MK = 220, MN = 1e5 + 3; ll n, a[MN], pref[MN], dp[MK][MN], p[MK][MN]; ll f(ll l, ll r, ll i) { ll a = pref[i] - pref[l - 1]; ll b = pref[r] - pref[i]; return a * b; } vi z; void bt(int a, int b) { if(!b)return; z.pb(b); if (a > 1) bt(a - 1, p[a][b]); } #define val(j) ((dp[a - 1][(j) - 1] + f(j, n, i))) int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i], pref[i] = pref[i - 1] + a[i]; } ll ans = -1, g = n - 1; cht x; for (int a = 1; a <= k; a++) { x.clear(); // if(a==1) x.add(vec(0, 0), 0); for (int i = 1; i < n; i++) { if(i>=a) { dp[a][i] = x.get(vec(1, pref[n]-pref[i]), p[a][i]) + pref[i]*(pref[n]-pref[i]); // p[a][i] = bc[-t.imag()]; // cout << -t.real() << " "; ans = max(ans, dp[a][i]); if (ans == dp[a][i]) g = i; }else dp[a][i] = dp[a-1][i]; x.add(vec(dp[a - 1][i], -pref[i]), i); } } cout << ans << '\n'; bt(k, g); set<int> xx; for(auto i : z) cout << i << " ", xx.insert(i); int v = 1; while(z.size() < k) { while(xx.count(v)){v++;} xx.insert(v); z.pb(v); cout << v << " "; } }

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

sequence.cpp: In function 'int main()':
sequence.cpp:124:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(z.size() < 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...