이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Solution
// Webbly, 27.01.2023
//
//
// Arsen ne katai
//
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("fast-loops")
/**
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC target("avx")
*/
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define flush cout.flush()
using namespace std;
const long long mod = (ll)1e9 + 7, mod3 = 998244353, inf = (ll)1e15, P = 997;
ll rnd(){
ll x = rand() << 15;
return rand() ^ x;
}
ll binpow (ll a, ll b){
ll ans = 1;
while(b){
if (b & 1){
ans *= a;
ans %= mod;
}
b >>= 1;
a *= a;
a %= mod;
}
return ans;
}
ll gcd(ll a, ll b){
return (b ? gcd(b, a % b) : a);
}
ll nums(ll g){
ll cur = 0;
while(g){
cur++, g /= 10;
}
return cur;
}
ll lcm(ll a, ll b){
return a / gcd(a, b) * b;
}
vector <ll> fac(ll n){
ll i = 2;
vector <ll> ans;
ll save = n;
while(i * i <= save){
while(n % i == 0){
ans.pb(i);
n /= i;
}
i++;
}
if (n > 1) ans.pb(n);
return ans;
}
ll get1(ll q, ll g){
ll cur = 1;
for (ll i = q; i > g; i--){
cur *= i;
}
return cur;
}
struct T{
ll cost, x, y;
};
struct tr{
ll x, y;
};
ll n, m, k, a[500005], b[500005], p[500005], dp[500005], t[500005 * 5];
string s;
void update(ll ind, ll v = 1, ll tl = 1, ll tr = n){
if (tl == tr){
t[v] = 1;
return;
}
ll tm = (tl + tr) >> 1;
if (ind <= tm) update(ind, v + v, tl, tm);
else update(ind, v + v + 1, tm + 1, tr);
t[v] = t[v + v] + t[v + v + 1];
}
ll get_min(ll l, ll r, ll v = 1, ll tl = 0, ll tr = n){
if (tl > r || l > tr) return n + 1;
if (tl == tr && !t[v]){
return tl;
}
ll tm = (tl + tr) >> 1;
ll lt = get_min(l, r, v + v, tl, tm);
if (lt != n) return lt;
return get_min(l, r, v + v + 1, tm + 1, tr);
}
ll get_max(ll l, ll r, ll v = 1, ll tl = 0, ll tr = n){
if (tl > r || l > tr) return 0;
if (tl == tr && !t[v]){
return tl;
}
ll tm = (tl + tr) >> 1;
ll lt = get_max(l, r, v + v + 1, tm + 1, tr);
if (lt != 0) return lt;
return get_max(l, r, v + v, tl, tm);
}
void query(){
cin >> n >> k;
if (n > 1000 || k > 200) return;
for (ll i = 1; i <= n; i++){
cin >> a[i];
p[i] = p[i - 1] + a[i];
}
ll ans = 0;
vector <ll> path;
for (ll j = 1; j <= k; j++){
ll cur = -inf, ind = 1;
for (ll i = 1; i < n; i++){
ll l = i, r = i;
if (t[i]) continue;
while(r < n && t[r] != 1) r++;
while(l > 1 && t[l - 1] != 1) l--;
if ((p[r] - p[i]) * (p[i] - p[l - 1]) > cur){
cur = (p[r] - p[i]) * (p[i] - p[l - 1]);
ind = i;
}
}
ans += cur;
t[ind] = 1;
path.pb(ind);
}
cout << ans << endl;
for (auto i : path) cout << i << ' ';
}
int main(){
//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ll TT = 1, tests = 1;
//cin >> TT;
while(TT--){
//cout << "Case " << tests << ": ";
query();
//tests++;
}
return 0;
}
/**
9 4
1 2 4 1 5 2 3 7 1
169 + 42 + 40 + 12 = 265
*/
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int main()':
sequence.cpp:249:16: warning: unused variable 'tests' [-Wunused-variable]
249 | ll TT = 1, tests = 1;
| ^~~~~
# | 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... |