제출 #855429

#제출 시각아이디문제언어결과실행 시간메모리
855429vjudge1Split the sequence (APIO14_sequence)C++17
0 / 100
2004 ms5268 KiB
// Bolatulu
#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define int long long
#define kanagattandirilmagandiktarinizdan ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define F first
#define S second
#define md (tl+tr)/2
#define TL v+v,tl,mid
#define TR v+v+1,mid+1,tr

#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")

using namespace std;

int binpow(int a,int n,int M) {
    if (n==0)
        return 1;
    if (n%2!=0)
        return (a * binpow(a,n-1,M))%M;
    int z=binpow(a,n/2,M);
    return (z*z)%M;
}

int rnd() {
    int x = rand() << 15;
    return rand() ^ x;
}

struct target {
    int l,r,x,y,ans;
};

bool cmp(target a, target b) {
    if (a.l==b.l)
        return a.r<b.r;
    return a.l<b.l;
}

const ll INF = 1e18+9;
const int N =  2e5+7;
const int M = 1e9+7;
const ll HZ = 1e5;
const int MAX = INT_MAX;
const int MIN = INT_MIN;
const db pi = 3.141592653;
const int P=31;

int n,a[N],ps[N];

pair <int,vector <int>> get(set <int> v1,set <int> v2,int ansum, vector <int> ans, bool u[N], int k) {
    if (!k)
        return {ansum,ans};
    int mx = -INF, pos, pos1 = -1,mxx=-INF,xm=-INF;
    vector <int> gg;
    for (int j = 1; j < n; j++) {
        if (u[j])
            continue;
        auto f = v1.upper_bound(j);
        f--;
        int z = *v2.lower_bound(j + 1), x = *f;
        if (z == j or x == j)
            continue;
        xm=max(xm,(ps[j] - ps[x]) * (ps[z - 1] - ps[j]));
    }
    for (int j = 1; j < n; j++) {
        if (u[j])
            continue;
        auto f = v1.upper_bound(j);
        f--;
        int z = *v2.lower_bound(j + 1), x = *f;
        if (z == j or x == j or (ps[j] - ps[x]) * (ps[z - 1] - ps[j])!=xm)
            continue;
        mx = (ps[j] - ps[x]) * (ps[z - 1] - ps[j]);
        u[j] = true;
        v1.insert(j), v2.insert(j + 1);
        ansum += mx;
        ans.push_back(j);
        pair <int,vector <int>> df=get(v1, v2, ansum, ans, u, k - 1);
        if (mxx<df.first) {
            mxx=df.first;
            gg=df.second;
        }
        u[j] = false;
        v1.erase(j), v2.erase(j + 1);
        ansum -= mx;
        ans.pop_back();
    }
    return {mxx,gg};
}

int k;
bool u[N];

void solve() {
    cin >> n >> k;
    for (int i=1;i<=n;i++)
        cin >> a[i],ps[i]=ps[i-1]+a[i];
    pair <int,vector <int>> anz=get({0},{n+1},0,{},u,k);
    int ansum=anz.first;
    vector <int> ans=anz.second;
    cout << ansum << '\n';
    sort (ans.begin(),ans.end());
    for (auto now : ans)
        cout << now << ' ';
}

signed main() {
    // freopen("sequence.in", "r", stdin);
    // freopen("sequence.out", "w", stdout);
    kanagattandirilmagandiktarinizdan
    int test = 1,count = 1;
    // cin >> test;
    while (test--) {
        // cout << "Case " << count << ": ";
        solve();
        if (test)
            cout << '\n';
        count++;
    }
    return 0;
}

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

sequence.cpp: In function 'std::pair<long long int, std::vector<long long int> > get(std::set<long long int>, std::set<long long int>, long long int, std::vector<long long int>, bool*, long long int)':
sequence.cpp:59:20: warning: unused variable 'pos' [-Wunused-variable]
   59 |     int mx = -INF, pos, pos1 = -1,mxx=-INF,xm=-INF;
      |                    ^~~
sequence.cpp:59:25: warning: unused variable 'pos1' [-Wunused-variable]
   59 |     int mx = -INF, pos, pos1 = -1,mxx=-INF,xm=-INF;
      |                         ^~~~
#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...