제출 #855452

#제출 시각아이디문제언어결과실행 시간메모리
855452vjudge1수열 (APIO14_sequence)C++17
0 / 100
1 ms604 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],md[15];
int n,k,ans,res;

void per(int i){
    if(i == k + 1){
        int res = 0;
        bool w = 0;
        if(v[0] == 1 && v[1] == 3 && v[2] == 5)w = 1;
        for(int j = 1;j <= 11;j++)md[j] = 0;
        for(int to : v){
            int z = 0,x = 0;
            for(int j =  to;j > 0;j--){
                if(md[j] == 1)break;
                z += a[j];
            }
            for(int j = to + 1;j <= n;j++){
                x += a[j];
                if(md[j] == 1)break;
            }

            res += (x * z);
            md[to] = 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){
                used[j] = 1;
                v.pb(j);
                per(i+ 1);
                v.pop_back();
                used[j] = 0;
            }
        }
    }
}


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: In function 'void per(int)':
sequence.cpp:25:14: warning: variable 'w' set but not used [-Wunused-but-set-variable]
   25 |         bool w = 0;
      |              ^
sequence.cpp: At global scope:
sequence.cpp:73:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   73 | 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...