제출 #855361

#제출 시각아이디문제언어결과실행 시간메모리
855361vjudge1Split the sequence (APIO14_sequence)C++17
50 / 100
2025 ms35048 KiB
//Bismillahir-Rahmanir-Rahim

#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pld pair <long double, long double>
#define ll long long
#define ld long double
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define skip continue
#define bpop(x) (ll)__builtin_popcountll(x)

using namespace std;

const int N = 1e4 + 7;
const int M = 1e2 + 7;
const int MAXA = 5e4 + 7;
const int inf = 1e18 + 7;
const ll INF = 1e18 + 7;
const ll MOD = 1e9 + 7;

pii dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

#define int long long

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

bool ok[N][207];
int n, k, a[N], pre[N], pr[N][207], dp[N][207];
int calc(int l, int r) {
    return pre[r] - pre[l - 1];
}
void subtask1234() {
    memset(dp, 0, sizeof dp), memset(pr, 0, sizeof pr);
    for (int i = 1;i <= n;i++)ok[i][1] = 1;
    for (int i = 2;i <= n;i++) {
        for (int j = 2;j <= min(i, k + 1);j++) {
            for (int last = 1;last < i;last++) {
                int x = dp[last][j - 1] + pre[last] * (pre[i] - pre[last]);
                if (ok[last][j - 1] && x >= dp[i][j])dp[i][j] = x, pr[i][j] = last, ok[i][j] = 1;
            }
        }
    }
    int ans = dp[n][k + 1];
    cout << ans << '\n';
    int pos = n, cur = k + 1;
    vector <int> path;
    while (cur > 0) {
        pos = pr[pos][cur], cur--;
        if (pos)path.pb(pos);
    }
    reverse(all(path));
    for (auto to : path)cout << to << ' ';
}
void solve() {
    cin >> n >> k;
    for (int i = 1;i <= n;i++)cin >> a[i], pre[i] = pre[i - 1] + a[i];
    subtask1234();
}
signed main() {
    //srand(time(NULL));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("milkorder.in", "r", stdin);
    //freopen("milkorder.out", "w", stdout);
    int test = 1;
    //cin >> test;
    for (int i = 1;i <= test;i++) {
        //cout << "Case " << i << ": ";
        solve();
    }
    return 0;
}

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

sequence.cpp:4: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    4 | #pragma comment(linker, "/stack:200000000")
      | 
sequence.cpp:26:22: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   26 | const int inf = 1e18 + 7;
      |                 ~~~~~^~~
#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...