제출 #434284

#제출 시각아이디문제언어결과실행 시간메모리
434284mat_v수열 (APIO14_sequence)C++14
100 / 100
1999 ms82608 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


ll maks;

int n,k;
ll niz[100005];
int gde[100001][201];
ll dp[100005];
ll dp2[100005];
ll pref[100005];

ll C(ll x, ll y){
    if(y >= x)return maks;
    return (pref[x] - pref[y]) * (pref[x] - pref[y]);
}
int idx;

void resi(int l, int r, int tl, int tr){
    if(l > r)return;
    int mid = (l + r) / 2;
    int koji = 0;
    ll val = maks;

    ff(j,tl,min(mid - 1,tr)){
        ll sta = dp[j] + C(mid,j);
        if(sta < val){
            val = sta;
            koji = j;
        }
    }
    gde[mid][idx] = koji;
    dp2[mid] = val;
    resi(l,mid-1,tl,koji);
    resi(mid+1,r,koji,tr);
}

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> n >> k;
    ff(i,1,n){cin >> niz[i]; pref[i] = pref[i - 1] + niz[i];}
    k++;
    maks = 1e9;
    maks *= maks;

    maks++;
    dp[0] = 0;
    ff(i,1,n){
        dp[i] = maks;
        dp2[i] = dp2[i - 1] = maks;
    }
    ff(i,1,k){
        idx = i;
        resi(0,n,0,n);
        ff(j,0,n){
            dp[j] = dp2[j];
            dp2[j] = maks;
        }
    }
    cout << (C(n,0) - dp[n])/2 << "\n";
    int sad = n;
    fb(i,k,1){
        sad = gde[sad][i];
        if(i > 1)cout << sad << " ";
    }
    return 0;
}
/*
7 3
4 1 3 4 0 2 3
*/

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

sequence.cpp: In function 'void resi(int, int, int, int)':
sequence.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
sequence.cpp:44:5: note: in expansion of macro 'ff'
   44 |     ff(j,tl,min(mid - 1,tr)){
      |     ^~
sequence.cpp: In function 'int main()':
sequence.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
sequence.cpp:63:5: note: in expansion of macro 'ff'
   63 |     ff(i,1,n){cin >> niz[i]; pref[i] = pref[i - 1] + niz[i];}
      |     ^~
sequence.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
sequence.cpp:70:5: note: in expansion of macro 'ff'
   70 |     ff(i,1,n){
      |     ^~
sequence.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
sequence.cpp:74:5: note: in expansion of macro 'ff'
   74 |     ff(i,1,k){
      |     ^~
sequence.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
sequence.cpp:77:9: note: in expansion of macro 'ff'
   77 |         ff(j,0,n){
      |         ^~
sequence.cpp:7:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
      |                           ^
sequence.cpp:84:5: note: in expansion of macro 'fb'
   84 |     fb(i,k,1){
      |     ^~
#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...