Submission #1037089

# Submission time Handle Problem Language Result Execution time Memory
1037089 2024-07-28T03:49:18 Z mindiyak Split the sequence (APIO14_sequence) C++14
0 / 100
9 ms 2396 KB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
void init()
{
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
#endif
}
void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

int n,k;
vi arr;
vl pre;
priority_queue<pair<ll,pair<int,pi>>> pq;
ll ans = 0;
vi ans_arr;

void calc(int l,int r){
    if(l>=r)return;
    ll tot = pre[r+1] - pre[l];
    ll sumt = tot/2;
    int pos = lower_bound(pre.begin(),pre.end(),sumt+pre[l]) - pre.begin();
    // cout << "create " << l << " " << r << " - " << tot << " " << sumt << " " << pos << " ";
    ll sums = (pre[pos] - pre[l]) * (pre[r+1] - pre[pos]);
    // cout << (pre[pos] - pre[l])  << " & " << (pre[r+1] - pre[pos]) << " " << sums << endl;
    pq.push({sums,{pos-1,{l,r}}});
}


void solve()
{
    cin >> n >> k;
    arr = vi (n);
    FOR(i,0,n)cin >> arr[i];
    pre = vl (n+1,0);
    FOR(i,1,n+1)pre[i] = pre[i-1] + arr[i-1];

    FOR(i,0,n+1)cout << pre[i] << " ";
    cout << endl;

    calc(0,n-1);

    while(ans_arr.size() < k){
        auto a = pq.top();pq.pop();
        // cout << a.F << " " << a.S.F << " " << a.S.S.F << " " << a.S.S.S << endl;
        ans += a.F;
        ans_arr.pb(a.S.F);
        calc(a.S.S.F,a.S.F);
        calc(a.S.F+1,a.S.S.S);
    }

    cout << ans << endl;
    FOR(i,0,k)cout << ans_arr[i] << " ";
    cout << endl;


}


int main()
{
    fastIO();
    // init();
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

Compilation message

sequence.cpp: In function 'void solve()':
sequence.cpp:84:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   84 |     while(ans_arr.size() < k){
      |           ~~~~~~~~~~~~~~~^~~
sequence.cpp: In function 'void init()':
sequence.cpp:42:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     freopen("input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     freopen("output.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Integer 8 violates the range [1, 6]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB declared answer doesn't correspond to the split scheme: declared = 0, real = 131300
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB position 5 occurs twice in split scheme
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB position 8 occurs twice in split scheme
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 516 KB declared answer doesn't correspond to the split scheme: declared = 0, real = 1187838
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 2396 KB declared answer doesn't correspond to the split scheme: declared = 0, real = 6892112
2 Halted 0 ms 0 KB -