답안 #134931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134931 2019-07-23T12:30:02 Z qrno 수열 (APIO14_sequence) C++14
0 / 100
28 ms 888 KB
#include <iostream>
#include <vector>
#include <set>
#include <queue>

using namespace std;

vector<int> numbers;
priority_queue<pair<int, pair<int, int> > > pieces;
set<int> splits;

int findSplit(int l, int r) {
    int totalSum = 0;
    for (int i = l; i < r; i++) {
        totalSum += numbers[i];
    }
    int lSum = 0;
    int rSum = totalSum;
    
    int ans = 0;

    int i;
    for (i = l; i < r; i++) {
        lSum += numbers[i];
        rSum -= numbers[i];

        if (lSum * rSum > ans)
            ans = lSum * rSum;
        if (lSum * rSum < ans) {
            lSum -= numbers[i];
            rSum += numbers[i];
            pieces.push(make_pair(lSum, make_pair(l, i)));
            pieces.push(make_pair(rSum, make_pair(i, r)));

            splits.insert(i);
            return ans;
        }
    }

    splits.insert(i);
    pieces.push(make_pair(lSum, make_pair(l, i)));
    pieces.push(make_pair(rSum, make_pair(i, r)));

    return ans;
}

int main() {

    int nAmount, sAmount;
    cin >> nAmount >> sAmount;

    int totalSum = 0;

    for (int i = 0; i < nAmount; i++) {
        int x; cin >> x;
        numbers.push_back(x);

        totalSum += x;
    }

    pieces.push(make_pair(totalSum, make_pair(0, nAmount)));

    int ans = 0;

    for (int i = 0; i < sAmount;) {
        pair<int, pair<int, int> > topPiece = pieces.top();
        pieces.pop();
        int l = topPiece.second.first;
        int r = topPiece.second.second;

        if (l != r+1) {
            int x = findSplit(topPiece.second.first, topPiece.second.second);
            ans += x;
            i++;
        }
    }

    cout << ans << endl;
    for (int num : splits)
        cout << num << " ";
    cout << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB contestant found the optimal answer: 108 == 108
2 Incorrect 2 ms 376 KB contestant didn't find the optimal answer: 951 < 999
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Integer 50 violates the range [1, 49]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 2 ms 256 KB contestant found the optimal answer: 311760000 == 311760000
3 Incorrect 2 ms 256 KB Integer 0 violates the range [1, 199]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Integer 1000 violates the range [1, 999]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 376 KB contestant didn't find the optimal answer: 1794250000 < 1818678304
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 888 KB declared answer doesn't correspond to the split scheme: declared = 2146621256, real = 6441588552
2 Halted 0 ms 0 KB -