답안 #566345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
566345 2022-05-22T09:03:10 Z XEMPLI5 수열 (APIO14_sequence) C++17
0 / 100
16 ms 1236 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;

    vector<int> trees(n), pref(n);

    for (int i = 0; i < n; i++)
    {
        cin >> trees[i];
        pref[i] = trees[i];
        if (i)
            pref[i] += pref[i - 1];
    }

    set<pair<int, int>> parts;
    parts.insert({0, n - 1});

    int ans = 0;
    vector<int> moves;

    for (int l = 0; l < k; l++)
    {
        int mxVal = 0, loc = -1, mst = -1, med = -1;
        for (auto e : parts)
        {
            int st = e.first, ed = e.second;
            int curVal = 0;
            for (int i = st; i < ed; i++)
            {
                int fpart = pref[i];
                if (st)
                    fpart -= pref[st - 1];
                int spart = pref[ed];
                spart -= pref[i];
                int curVal = spart * fpart;
                if (curVal >= mxVal)
                {
                    mxVal = curVal;
                    loc = i;
                    mst = st;
                    med = ed;
                }
            }
        }
        if (loc != -1)
        {
            ans += mxVal;
            moves.push_back(loc + 1);
            parts.erase(parts.find({mst, med}));
            parts.insert({mst, loc});
            parts.insert({loc + 1, med});
        }
        else
            break;
    }
    cout << ans << '\n';
    for (auto e : moves)
    {
        cout << e << ' ';
    }
    return 0;
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:32:17: warning: unused variable 'curVal' [-Wunused-variable]
   32 |             int curVal = 0;
      |                 ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB contestant found the optimal answer: 108 == 108
2 Incorrect 1 ms 340 KB contestant didn't find the optimal answer: 951 < 999
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB contestant didn't find the optimal answer: 1093726 < 1093956
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 1 ms 212 KB contestant found the optimal answer: 311760000 == 311760000
3 Incorrect 1 ms 300 KB declared answer doesn't correspond to the split scheme: declared = 646158965, real = 1989216017013
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 296 KB contestant didn't find the optimal answer: 21419072 < 21503404
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 312 KB contestant didn't find the optimal answer: 1794250000 < 1818678304
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 1236 KB declared answer doesn't correspond to the split scheme: declared = 2147100203, real = 15032002091
2 Halted 0 ms 0 KB -