답안 #498404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498404 2021-12-25T06:27:38 Z kingline 수열 (APIO14_sequence) C++17
11 / 100
2000 ms 1868 KB
/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
//#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
//#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
#define int long long
#define pii pair < int, int >
#define pll pair < long long, long long >

using namespace std;

typedef long long ll;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int n, k, a[N], res, use, pref[N], ans;

vector < int > dv;
void rec(int l, int r, int last) {
    if(l >= r) return;
    last++;
    while(last < dv.size() && dv[last] < l) last++;
    if(last == dv.size() || r <= dv[last]) return;
    int lef = pref[dv[last]] - pref[l - 1], righ = pref[r] - pref[dv[last]];
    res += lef * righ;
    use++;
    rec(l, dv[last], last);
    rec(dv[last] + 1, r, last);
}

vector < int > path;
void found(int pos, int last) {
    if(pos == k) {
        rec(1, n, -1);
        if(res >= ans && use == k) {
            ans = res;
            path = dv;
        }
        use = 0;
        res = 0;
        return;
    }
    for(int i = last + 1; i <= n; i++) {
        dv.pb(i);
        found(pos + 1, i);
        dv.pop_back();
    }
}

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //file("pieaters");
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        pref[i] = pref[i - 1] + a[i];
    }
    found(0, 0);
    cout << ans << endl;
    for(int i = 0; i < path.size(); i++) {
        cout << path[i] << " ";
    }
}
/*
7 3
4 1 3 4 0 2 3
*/











Compilation message

sequence.cpp: In function 'void rec(long long int, long long int, long long int)':
sequence.cpp:32:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     while(last < dv.size() && dv[last] < l) last++;
      |           ~~~~~^~~~~~~~~~~
sequence.cpp:33:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     if(last == dv.size() || r <= dv[last]) return;
      |        ~~~~~^~~~~~~~~~~~
sequence.cpp: At global scope:
sequence.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   60 | main() {
      | ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:72:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int i = 0; i < path.size(); i++) {
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB contestant found the optimal answer: 108 == 108
2 Correct 0 ms 204 KB contestant found the optimal answer: 999 == 999
3 Correct 0 ms 204 KB contestant found the optimal answer: 0 == 0
4 Correct 1 ms 204 KB contestant found the optimal answer: 1542524 == 1542524
5 Correct 0 ms 204 KB contestant found the optimal answer: 4500000000 == 4500000000
6 Correct 1 ms 204 KB contestant found the optimal answer: 1 == 1
7 Correct 0 ms 204 KB contestant found the optimal answer: 1 == 1
8 Correct 0 ms 204 KB contestant found the optimal answer: 1 == 1
9 Correct 0 ms 204 KB contestant found the optimal answer: 100400096 == 100400096
10 Correct 0 ms 204 KB contestant found the optimal answer: 900320000 == 900320000
11 Correct 0 ms 204 KB contestant found the optimal answer: 3698080248 == 3698080248
12 Correct 0 ms 204 KB contestant found the optimal answer: 3200320000 == 3200320000
13 Correct 0 ms 204 KB contestant found the optimal answer: 140072 == 140072
14 Correct 0 ms 204 KB contestant found the optimal answer: 376041456 == 376041456
15 Correct 0 ms 204 KB contestant found the optimal answer: 805 == 805
16 Correct 0 ms 204 KB contestant found the optimal answer: 900189994 == 900189994
17 Correct 0 ms 204 KB contestant found the optimal answer: 999919994 == 999919994
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 1 ms 204 KB contestant found the optimal answer: 302460000 == 302460000
3 Execution timed out 2073 ms 204 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 204 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 33 ms 204 KB contestant found the optimal answer: 311760000 == 311760000
3 Execution timed out 2073 ms 332 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2045 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2023 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2074 ms 1868 KB Time limit exceeded
2 Halted 0 ms 0 KB -