답안 #572182

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572182 2022-06-03T23:34:55 Z teki 수열 (APIO14_sequence) C++11
0 / 100
29 ms 3908 KB
#include <bits/stdc++.h>

typedef long long ll;

#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
#define MN 1000000001

using namespace std;

int main()
{
    #if LOCAL_DEBUG
        fstream cin("in.txt");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll n,k;
    cin>>n>>k;

    ll niza[n];
    for (ll i = 0; i<n; i++) cin>>niza[i];

    set<ll> podelbi;
    podelbi.insert(n-1);

    ll res = 0;

    for (ll ctr = 1; ctr<=k; ctr++) {
        vector<pair<pair<ll,ll>,ll>> site;
        /// start, end, zbir!
        auto itPod = podelbi.begin();
        ll zbir = 0, s = 0;

        for (ll j = 0; j<n; j++) {
            zbir += niza[j];

            if (*itPod == j) {
                site.pb({{s,j},zbir});
                s = j+1;
                zbir = 0;
                itPod++;
            }
        }

        ll ctr2 = 0, l = site[0].first.first, r = site[0].first.second, zb = site[0].second;
        vector<pair<ll,ll>> mozni[ctr];
        ll zbMont = 0;

        for (ll j = 0; j<n; j++) {
            if (r < j) {
                ctr2++;
                l = site[ctr2].first.first;
                r = site[ctr2].first.second;
                zb = site[ctr2].second;
                zbMont = 0;
            }

            zbMont += niza[j];

            mozni[ctr2].pb({(zb-zbMont)*zbMont,j});
        }

        vector<pair<ll,ll>> vistina;
        for (ll j = 0; j<ctr; j++) sort(mozni[j].rbegin(),mozni[j].rend());
        for (ll j = 0; j<ctr; j++) vistina.pb(mozni[j][0]);

        sort(vistina.rbegin(), vistina.rend());
        podelbi.insert(vistina[0].second);

        res += vistina[0].first;
    }

    cout<<res<<endl;
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:49:22: warning: variable 'l' set but not used [-Wunused-but-set-variable]
   49 |         ll ctr2 = 0, l = site[0].first.first, r = site[0].first.second, zb = site[0].second;
      |                      ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 324 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 316 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 824 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 3908 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -