Submission #893916

# Submission time Handle Problem Language Result Execution time Memory
893916 2023-12-27T16:57:14 Z kigash Split the sequence (APIO14_sequence) C++17
50 / 100
105 ms 13344 KB
#include "bits/stdc++.h"
using namespace std;       

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using ll = long long;
using ld = long double;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
void IOIGold2024_InshAllah() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
ll binmul(ll a, ll b, ll c) { ll res = 0; while(b) { if(b&1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; }
ll binpow(ll a, ll b, ll c) { ll res = 1; while(b) { if(b&1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; }
template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ld rnd() { return rng()%INT_MAX*1.0/INT_MAX; }

const ll inf = 1e18+7, MX = LLONG_MAX, MN = LLONG_MIN;
const ll mod = 1e9+7, N = 3e5+5;
ll a[N], pr[N], dp[1005][205];

void kigash() {
    ll n, k, x = 1, mx = 0;
    cin>>n>>k;
    for(ll i=1; i<=n; i++) cin>>a[i], pr[i] = pr[i-1]+a[i];
    for(ll i=1; i<=n; i++) {
        for(ll j=1; j<=min(i, k); j++) {
            for(ll l=j-1; l<i-(i==n); l++) {
                dp[i][j] = max(dp[i][j], dp[l][j-1]+(pr[i]-pr[l])*(pr[n]-pr[i]));
            }
        }
        if(i>=k && dp[i][k]>mx) mx = dp[i][k], x = i;
    }
    vector<ll> ans;
    cout<<mx<<"\n";
    ans.pb(x);
    while(k--) {
        ll pos = -1;
        for(ll i=k; i<x-(x==n); i++) {
            if(dp[x][k+1]==dp[i][k]+(pr[x]-pr[i])*(pr[n]-pr[x])) {
                pos = i;
                break;
            }
        }
        x = pos;
        if(k) ans.pb(x);
    }
    reverse(all(ans));
    for(auto x: ans) cout<<x<<" ";
    return;
}

signed main(/*Kigash Amir*/) {
    // freopen("");
    IOIGold2024_InshAllah();
    ll tt = 1;
    // cin>>tt;
    for(ll i=1; i<=tt; i++) {
        kigash();
    }
}

Compilation message

sequence.cpp: In function 'void freopen(std::string)':
sequence.cpp:17:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:17:73: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB contestant found the optimal answer: 108 == 108
2 Correct 1 ms 4444 KB contestant found the optimal answer: 999 == 999
3 Correct 1 ms 4440 KB contestant found the optimal answer: 0 == 0
4 Correct 1 ms 4444 KB contestant found the optimal answer: 1542524 == 1542524
5 Correct 1 ms 4548 KB contestant found the optimal answer: 4500000000 == 4500000000
6 Correct 1 ms 4440 KB contestant found the optimal answer: 1 == 1
7 Correct 1 ms 4444 KB contestant found the optimal answer: 1 == 1
8 Correct 1 ms 4444 KB contestant found the optimal answer: 1 == 1
9 Correct 1 ms 4444 KB contestant found the optimal answer: 100400096 == 100400096
10 Correct 1 ms 4440 KB contestant found the optimal answer: 900320000 == 900320000
11 Correct 1 ms 4444 KB contestant found the optimal answer: 3698080248 == 3698080248
12 Correct 1 ms 4444 KB contestant found the optimal answer: 3200320000 == 3200320000
13 Correct 1 ms 4444 KB contestant found the optimal answer: 140072 == 140072
14 Correct 1 ms 4444 KB contestant found the optimal answer: 376041456 == 376041456
15 Correct 1 ms 4444 KB contestant found the optimal answer: 805 == 805
16 Correct 1 ms 4536 KB contestant found the optimal answer: 900189994 == 900189994
17 Correct 1 ms 4444 KB contestant found the optimal answer: 999919994 == 999919994
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 1 ms 4444 KB contestant found the optimal answer: 302460000 == 302460000
3 Correct 1 ms 4444 KB contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 1 ms 4444 KB contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 1 ms 4444 KB contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 1 ms 4444 KB contestant found the optimal answer: 933702 == 933702
7 Correct 1 ms 4444 KB contestant found the optimal answer: 25082842857 == 25082842857
8 Correct 1 ms 4444 KB contestant found the optimal answer: 687136 == 687136
9 Correct 1 ms 4444 KB contestant found the optimal answer: 27295930079 == 27295930079
10 Correct 1 ms 4444 KB contestant found the optimal answer: 29000419931 == 29000419931
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 1 ms 4700 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 3 ms 4700 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 1 ms 4700 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 3 ms 4700 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Correct 3 ms 4696 KB contestant found the optimal answer: 107630884 == 107630884
7 Correct 3 ms 4696 KB contestant found the optimal answer: 475357671774 == 475357671774
8 Correct 2 ms 4700 KB contestant found the optimal answer: 193556962 == 193556962
9 Correct 1 ms 4700 KB contestant found the optimal answer: 482389919803 == 482389919803
10 Correct 2 ms 4736 KB contestant found the optimal answer: 490686959791 == 490686959791
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5980 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 3 ms 5980 KB contestant found the optimal answer: 140412195 == 140412195
3 Correct 105 ms 5956 KB contestant found the optimal answer: 49729674225461 == 49729674225461
4 Correct 3 ms 5980 KB contestant found the optimal answer: 37485571387523 == 37485571387523
5 Correct 103 ms 6008 KB contestant found the optimal answer: 679388326 == 679388326
6 Correct 91 ms 5972 KB contestant found the optimal answer: 4699030287 == 4699030287
7 Correct 103 ms 6036 KB contestant found the optimal answer: 12418819758185 == 12418819758185
8 Correct 104 ms 5972 KB contestant found the optimal answer: 31093317350 == 31093317350
9 Correct 25 ms 5916 KB contestant found the optimal answer: 12194625429236 == 12194625429236
10 Correct 47 ms 5968 KB contestant found the optimal answer: 12345131038664 == 12345131038664
# Verdict Execution time Memory Grader output
1 Runtime error 36 ms 13136 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 40 ms 13344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -