이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <map>
using namespace std;
#define ll long long
#define pb push_back
#define el '\n'
#define mpair make_pair
#define MASK(i) (1LL << (i))
#define BIT(mask, i) (((mask) >> (i)) & 1)
/* Author: Pham Gia Phuoc */
const ll MOD = 998244353;
template <class T1, class T2>
void add(T1 &a, T2 b){
a += b;
if(a >= MOD) a -= MOD;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if(a > b){a = b; return true;} return false;
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if(a < b){a = b; return true;} return false;
}
/** END OF TEMPLATE. DRINK A CUP OF COFFEE BEFORE READING MY CODE **/
const int MAX = 2222;
const ll INF = (ll) 1e18 + 7LL;
int numVal, numSplit;
ll values[MAX];
void init(){
cin >> numVal >> numSplit;
for(int i = 1; i <= numVal; i++) cin >> values[i];
}
void solveSubtask1(){
int ans = 0, Mask = 0;
for(int i = 1; i <= numVal; i++) values[i] += values[i - 1];
for(int mask = 0; mask < MASK(numVal - 1); mask++)if(__builtin_popcount(mask) == numSplit){
int lastBit = 0; ll tmp = 0;
for(int i = 1; i < numVal; i++) if(BIT(mask, i - 1)){
tmp += (values[numVal] - values[i]) * (values[i] - values[lastBit]);
lastBit = i;
}
if(maximize(ans, tmp))Mask = mask;
}
cout << ans << el;
for(int i = 1; i < numVal; i++) if(BIT(Mask, i - 1)) cout << i << ' ';
}
void solve(){
if(numSplit <= 10 && numVal <= 10) solveSubtask1();
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
init();
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |