제출 #363760

#제출 시각아이디문제언어결과실행 시간메모리
363760BartolM수열 (APIO14_sequence)C++17
28 / 100
407 ms5484 KiB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const ll MAX=(ll)INF*INF;
const int N=1005;
const int K=202;

int n, k;
ll dp[N][K];
ll pref[N];
int bac[N][K];

void solve() {
    fill(dp[0], dp[0]+K, -MAX);
    dp[0][0]=0;
    for (int i=1; i<=n; ++i) {
        for (int j=1; j<=k; ++j) {
            for (int l=0; l<i; ++l) {
                ll curr=dp[l][j-1]+pref[l]*(pref[i]-pref[l]);
                if (curr>dp[i][j]) dp[i][j]=curr, bac[i][j]=l;
            }
        }
    }
    printf("%lld\n", dp[n][k]);
    pii pp=mp(n, k);
    while (pp.Y) {
        pp.X=bac[pp.X][pp.Y--];
        printf("%d ", pp.X);
    }
}

void load() {
    scanf("%d %d", &n, &k);
    for (int i=1; i<=n; ++i) {
        scanf("%lld", &pref[i]);
        pref[i]+=pref[i-1];
    }
}

int main() {
    load();
    solve();
    return 0;
}

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

sequence.cpp: In function 'void load()':
sequence.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
sequence.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |         scanf("%lld", &pref[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
#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...