제출 #48246

#제출 시각아이디문제언어결과실행 시간메모리
48246TheDarkning수열 (APIO14_sequence)C++17
11 / 100
272 ms24308 KiB
/**
                  ▄█▀ ▀█▀ ▄▀▄ █▀ █▄█▄█ ▄▀▄ █▀ ▄█▀
                  <⇋⇋⇋⋛∰≓⊂(⌒,_ゝ⌒)⊃≓∰⋛⇋⇋⇋>

            ♔♕♖♗♘♙ ☜❷☞✪ ィℋ६ ≈ ᗫẵℜℵĬŊĞ ✪☜❷☞ ♚♛♜♝♞♟
            ♔♕♖♗♘♙                             ♚♛♜♝♞♟
                      ˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙
7 3
4 1 3 4 0 2 3

**/

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <time.h>
#include <map>
#include <deque>
#include <assert.h>
#include <queue>
#include <string>
#include <memory.h>
#include <set>
#include <math.h>

#define sz(s) s.size()
#define pb emplace_back
#define fr first
#define sc second
#define mk make_pair
#define all(s) s.begin(), s.end()
#define ok puts("ok");

using namespace std;

const int N = 1e4 + 5;
const int inf = 1e9 + 7;

int n, k, ar[N], pref[N], pr[209][N], last = 1, cur = 1;

long long dp[209][N];

main(){
    cin >> n >> k;
    for( int i = 1; i <= n; i++ ){
        cin >> ar[i];
        pref[ i ] = pref[ i - 1 ] + ar[ i ];
    }
    k++;
    for( int i = 1; i <= k; i++ ){
            last = 1;
            cur = 1;
        for( int j = 1; j <= n; j++ ){
            for( int kk = last; kk <= j;kk++ ){
                if( dp[ i ][ j ] <= dp[ i - 1 ][ kk - 1 ] + ( pref[ j ] - pref[ kk - 1 ] ) * ( pref[ n ] - pref[j] )  ){
                    dp[ i ][ j ] = max( dp[ i ][ j ], dp[ i - 1 ][ kk - 1 ] + (pref[j] - pref[kk - 1]) * (pref[n] - pref[j]) );
                    pr[ i ][ j ] = kk - 1;
                    cur = kk;
                }
            }
            last = cur;
        }
    }
    cout << dp[ k ][ n ] << endl;
    while( k > 1 ){
        cout << pr[ k ][ n ] << ' ';
        n = pr[ k ][ n ];
        k--;
    }
}

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

sequence.cpp:45:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 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...