답안 #130102

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
130102 2019-07-14T00:07:48 Z mlyean00 수열 (APIO14_sequence) C++14
11 / 100
2000 ms 1912 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    vector<ll> pref(n + 1, 0);
    partial_sum(a.begin(), a.end(), pref.begin() + 1);

    vector<int> p(n - 1);
    iota(p.begin(), p.end(), 1);

    ll max_pts = -1;
    vector<int> v(k);
    do {
        ll pts = 0;
        set<int> s {0, n};
        for (int i = 0; i < k; ++i) {
            int l = *prev(s.lower_bound(p[i]));
            int r = *s.lower_bound(p[i]);
            pts += (pref[p[i]] - pref[l]) * (pref[r] - pref[p[i]]);
            s.insert(p[i]);
        }

        if (pts > max_pts) {
            max_pts = pts;
            copy(p.begin(), p.begin() + k, v.begin());
        }
    } while (next_permutation(p.begin(), p.end()));

    cout << max_pts << endl;
    for (int i : v) {
        cout << i << ' ';
    }
    cout << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB contestant found the optimal answer: 108 == 108
2 Correct 99 ms 256 KB contestant found the optimal answer: 999 == 999
3 Correct 2 ms 256 KB contestant found the optimal answer: 0 == 0
4 Correct 173 ms 504 KB contestant found the optimal answer: 1542524 == 1542524
5 Correct 306 ms 376 KB contestant found the optimal answer: 4500000000 == 4500000000
6 Correct 75 ms 252 KB contestant found the optimal answer: 1 == 1
7 Correct 75 ms 476 KB contestant found the optimal answer: 1 == 1
8 Correct 75 ms 256 KB contestant found the optimal answer: 1 == 1
9 Correct 123 ms 376 KB contestant found the optimal answer: 100400096 == 100400096
10 Correct 122 ms 256 KB contestant found the optimal answer: 900320000 == 900320000
11 Correct 123 ms 504 KB contestant found the optimal answer: 3698080248 == 3698080248
12 Correct 148 ms 376 KB contestant found the optimal answer: 3200320000 == 3200320000
13 Correct 18 ms 360 KB contestant found the optimal answer: 140072 == 140072
14 Correct 2 ms 256 KB contestant found the optimal answer: 376041456 == 376041456
15 Correct 147 ms 376 KB contestant found the optimal answer: 805 == 805
16 Correct 122 ms 376 KB contestant found the optimal answer: 900189994 == 900189994
17 Correct 147 ms 376 KB contestant found the optimal answer: 999919994 == 999919994
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2043 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2050 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2041 ms 380 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2060 ms 504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2047 ms 1912 KB Time limit exceeded
2 Halted 0 ms 0 KB -