Submission #48248

#TimeUsernameProblemLanguageResultExecution timeMemory
48248TheDarkningSplit the sequence (APIO14_sequence)C++17
71 / 100
467 ms32252 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 int long long #define all(s) s.begin(), s.end() #define ok puts("ok"); using namespace std; const int N = 1e4 + 5; const int inf = 1e18 + 7; int n, k, ar[N], pref[N], dp[209][N], pr[209][N], last = 1, cur = 1; main(){ cin >> n >> k; for( int i = 1; i <= n; i++ ){ cin >> ar[i]; pref[ i ] = pref[ i - 1 ] + ar[ i ]; } k++; last = 1; for( int i = 1; i <= k; i++ ){ 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--; } }

Compilation message (stderr)

sequence.cpp:44: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...