Submission #414337

# Submission time Handle Problem Language Result Execution time Memory
414337 2021-05-30T10:48:35 Z AmineWeslati Split the sequence (APIO14_sequence) C++14
50 / 100
2000 ms 25548 KB
//Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
    return a + rng() % (b - a + 1);
}
#ifndef LOCAL  
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl; 
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;

void IO() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////

int N,K; 
vi a(MX,0);

ll get(int i, int j){
	if(i>j) return 0;
	return a[j]-a[i-1];
}

int main() {
    boost; IO();

    cin>>N>>K;
    FOR(i,1,N+1) cin>>a[i];
    FOR(i,1,N+1) a[i]+=a[i-1];

    vector<vector<ll>>dp(N+1,vector<ll>(K+2,-INF));
    vector<vi>prev(N+1,vi(K+2,-1));

    dp[0][0]=0;
    FOR(i,1,N+1) FOR(k,1,K+2){
    	FOR(j,0,i) if(ckmax(dp[i][k],dp[j][k-1]+get(j+1,i)*get(i+1,N)))
    		prev[i][k]=j;
    }
    cout << dp[N][K+1] << endl;

    vi vec;
    int i=N,k=K+1; 
    while(1){
    	i=prev[i][k];
    	k--;
    	if(!i) break;
    	vec.pb(i);
    }
    reverse(all(vec));
    for(auto x: vec) cout << x << ' ';
    cout << endl;

    

    return 0;
}
//Change your approach 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1100 KB contestant found the optimal answer: 108 == 108
2 Correct 2 ms 1100 KB contestant found the optimal answer: 999 == 999
3 Correct 1 ms 1100 KB contestant found the optimal answer: 0 == 0
4 Correct 1 ms 1100 KB contestant found the optimal answer: 1542524 == 1542524
5 Correct 1 ms 1100 KB contestant found the optimal answer: 4500000000 == 4500000000
6 Correct 1 ms 1100 KB contestant found the optimal answer: 1 == 1
7 Correct 1 ms 1224 KB contestant found the optimal answer: 1 == 1
8 Correct 1 ms 1100 KB contestant found the optimal answer: 1 == 1
9 Correct 1 ms 1100 KB contestant found the optimal answer: 100400096 == 100400096
10 Correct 1 ms 1100 KB contestant found the optimal answer: 900320000 == 900320000
11 Correct 1 ms 1100 KB contestant found the optimal answer: 3698080248 == 3698080248
12 Correct 1 ms 1100 KB contestant found the optimal answer: 3200320000 == 3200320000
13 Correct 2 ms 1100 KB contestant found the optimal answer: 140072 == 140072
14 Correct 1 ms 1100 KB contestant found the optimal answer: 376041456 == 376041456
15 Correct 2 ms 1100 KB contestant found the optimal answer: 805 == 805
16 Correct 1 ms 1100 KB contestant found the optimal answer: 900189994 == 900189994
17 Correct 1 ms 1100 KB contestant found the optimal answer: 999919994 == 999919994
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1100 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 1 ms 1100 KB contestant found the optimal answer: 302460000 == 302460000
3 Correct 1 ms 1100 KB contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 1 ms 1100 KB contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 1 ms 1112 KB contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 1 ms 1100 KB contestant found the optimal answer: 933702 == 933702
7 Correct 1 ms 1100 KB contestant found the optimal answer: 25082842857 == 25082842857
8 Correct 2 ms 1108 KB contestant found the optimal answer: 687136 == 687136
9 Correct 1 ms 1100 KB contestant found the optimal answer: 27295930079 == 27295930079
10 Correct 2 ms 1028 KB contestant found the optimal answer: 29000419931 == 29000419931
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1100 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 2 ms 1100 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 18 ms 1484 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 2 ms 1116 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 10 ms 1468 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Correct 13 ms 1484 KB contestant found the optimal answer: 107630884 == 107630884
7 Correct 15 ms 1484 KB contestant found the optimal answer: 475357671774 == 475357671774
8 Correct 4 ms 1228 KB contestant found the optimal answer: 193556962 == 193556962
9 Correct 3 ms 1100 KB contestant found the optimal answer: 482389919803 == 482389919803
10 Correct 5 ms 1228 KB contestant found the optimal answer: 490686959791 == 490686959791
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1112 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 6 ms 1228 KB contestant found the optimal answer: 140412195 == 140412195
3 Correct 348 ms 3536 KB contestant found the optimal answer: 49729674225461 == 49729674225461
4 Correct 7 ms 1228 KB contestant found the optimal answer: 37485571387523 == 37485571387523
5 Correct 358 ms 3532 KB contestant found the optimal answer: 679388326 == 679388326
6 Correct 313 ms 3204 KB contestant found the optimal answer: 4699030287 == 4699030287
7 Correct 344 ms 3556 KB contestant found the optimal answer: 12418819758185 == 12418819758185
8 Correct 352 ms 3540 KB contestant found the optimal answer: 31093317350 == 31093317350
9 Correct 81 ms 1612 KB contestant found the optimal answer: 12194625429236 == 12194625429236
10 Correct 167 ms 2124 KB contestant found the optimal answer: 12345131038664 == 12345131038664
# Verdict Execution time Memory Grader output
1 Correct 642 ms 2380 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Correct 439 ms 2380 KB contestant found the optimal answer: 1326260195 == 1326260195
3 Execution timed out 2095 ms 25548 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 13644 KB Time limit exceeded
2 Halted 0 ms 0 KB -