제출 #536096

#제출 시각아이디문제언어결과실행 시간메모리
536096mansur수열 (APIO14_sequence)C++17
49 / 100
69 ms131072 KiB
#include<bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ll long long #define pb push_back #define sz(a) a.size() #define nl '\n' #define popb pop_back() #define ld double #define ull unsigned long long #define ff first #define ss second #define fix fixed << setprecision #define pii pair<int, int> #define E exit (0) #define int long long const int inf = 1e15, N = 1e5 + 5, mod = 1e9 + 7; double eps = 1e-6; bool fl = 0; vector<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int ntr(pii a, pii b) { int x = b.ff - a.ff; int y = a.ss - b.ss; return (x + y - 1) / (y); } void solve() { int n, k; cin >> n >> k; int p[n + 1]; pii pr[n + 1][k + 1]; p[0] = 0; for (int i = 1, a; i <= n; i++) { cin >> a; p[i] = p[i - 1] + a; } int dp[n + 1][k + 1]; for (int i = 1; i <= n; i++) { for (int s = 1; s <= k; s++) dp[i][s] = -inf; } for (int i = 0; i <= k; i++) dp[0][i] = 0; vector<pair<pii, pii>> s; s.pb({{-inf, -1}, {0, 0}}); for (int j = 0; j <= k; j++) { int l = 0; for (int i = 1; i <= n; i++) { while (l < sz(s) && s[l].ff.ff <= p[i]) l++; dp[i][j] = max(dp[i - 1][j], s[l - 1].ss.ff + s[l - 1].ss.ss * p[i]); if (dp[i][j] == dp[i - 1][j]) { pr[i][j] = {i - 1, j}; }else { pr[i][j] = {s[l - 1].ff.ss, j - 1}; } } s.clear(); for (int i = 1; i <= n; i++) { int a = dp[i][j] - p[i] * p[i], b = p[i]; if (sz(s) && a == s.back().ss.ff && b == s.back().ss.ss) continue; int ps = -inf; while (sz(s) && ntr({a, b}, s.back().ss) <= s.back().ff.ff) s.popb; if (sz(s)) ps = ntr({a, b}, s.back().ss); s.pb({{ps, i}, {a, b}}); } } cout << dp[n][k] << nl; vector<int> ans; int i = n, j = k; while (j > 0) { int i1 = pr[i][j].ff, j1 = pr[i][j].ss; if (j1 == j) { i = i1, j = j1; continue; } ans.pb(i1); i = i1, j = j1; } for (auto x: ans) cout << x << ' '; } main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(NULL); cin.tie(NULL); int tp = 1; if (fl) cin >> tp; while (tp--) solve(); }

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

sequence.cpp: In function 'void solve()':
sequence.cpp:58:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |    while (l < sz(s) && s[l].ff.ff <= p[i]) l++;
      |             ^
sequence.cpp: At global scope:
sequence.cpp:91:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   91 | main() {
      | ^~~~
#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...