제출 #855441

#제출 시각아이디문제언어결과실행 시간메모리
855441vjudge1수열 (APIO14_sequence)C++17
0 / 100
5 ms460 KiB
/// tree bends in youth
/// 1.10.2023
/// success is doing same thing in every single day!!!
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
using namespace std;
const ll N =2e5 + 5;
const ll NN = 2e5;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int a[15];
vector <int> v;
vector <int> p;
bool used[15];
int n,k,ans,res;

void per(int i){
    if(i == k + 1){
        if(res >ans){
            ans = res;
            p.clear();
            for(int to : v)p.pb(to);
        }
    }
    else{
        for(int j = 1;j <= n;j++){
            if(used[j] == 0){
                int z = 0,x = 0;
                for(int g = j;g > 0;g--){
                    if(used[g] == 1)break;
                    z += a[g];
                }
                for(int g = j + 1;g <= n;g++){
                    x += a[g];
                    if(used[g] == 1)break;
                }
                if(z > 0 && x > 0)res += (x * z);
                used[j] = 1;
                v.pb(j);
                per(i + 1);
                v.pop_back();
                used[j] = 0;
                if(z > 0 && x > 0)res -= (x * z);
            }
        }
    }
}


void solve(){
    cin >> n >> k;
    for(int i = 1;i <= n;i++)cin >> a[i];
    per(1);
    cout << ans << '\n';
    for(int to : p){
        cout<<to << ' ';
    }
}
main (){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    freopen("moocrypt.in","r",stdin);
//    freopen("moocrypt.out","w",stdout);

    ll abdu= 1;
   // cin >> abdu;
    for(ll i = 1;i <= abdu;i++){
//        cout << "Case " << i << ": ";
        solve();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp:64:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   64 | main (){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...