Submission #713988

# Submission time Handle Problem Language Result Execution time Memory
713988 2023-03-23T12:15:18 Z vqpahmad Split the sequence (APIO14_sequence) C++14
0 / 100
2000 ms 7824 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define endl '\n'
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mod = 1e9 + 7;
const int N = 1e6 + 15;
const ll inf = 1e18;
set<int> av;
set<int> ct;
const int off = (1<<20);
int t[off*2];
int combine(int u,int v){
	return u+v;
}
void update(int i,int u){
	i+=off;
	t[i] = u;
	while (i/=2){
		t[i] = combine(t[i*2],t[i*2+1]);
	}
}
int get(int l, int r, int idx=1, int lo=0, int hi=off){
	if (lo>=r||hi<=l) return 0;
	if (lo>=l&&hi<=r) return t[idx];
	int mi = (lo+hi)/2;
	return combine(get(l,r,idx*2,lo,mi),get(l,r,idx*2+1,mi,hi));
}
int32_t main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,k; cin >> n >> k;
	ct.insert(0);
	ct.insert(n);
	vector<int> a(n);
	for (int i=0;i<n;i++){
		cin >> a[i];
		update(i,a[i]);
	}
	for (int i=1;i<=n-1;i++) av.insert(i);
	int ans = 0;
	for (int i=0;i<k;i++){
		int best = 0;
		int pos = *av.begin();
		for (auto it : av){
			int lo = *--ct.upper_bound(it);
			int hi = *ct.upper_bound(it);
			int cur = get(lo,it)*get(it,hi);
			if (cur > best){
				best = cur;
				pos = it;
			}
		}
		ct.insert(pos);
		av.erase(pos);
		ans += best;
	}
	cout << ans << '\n';
	for (auto it : ct){
		if (it==0||it==n) continue;
		cout << it << ' ';
	}
	cout << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB contestant found the optimal answer: 108 == 108
2 Incorrect 1 ms 340 KB contestant didn't find the optimal answer: 951 < 999
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB contestant didn't find the optimal answer: 1093726 < 1093956
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 1 ms 340 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 6 ms 340 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 1 ms 340 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Incorrect 6 ms 328 KB contestant didn't find the optimal answer: 1019625813 < 1019625819
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB contestant didn't find the optimal answer: 21419072 < 21503404
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 980 KB contestant didn't find the optimal answer: 1794250000 < 1818678304
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 138 ms 7372 KB contestant found the optimal answer: 19795776960 == 19795776960
2 Correct 131 ms 7496 KB contestant found the optimal answer: 19874432173 == 19874432173
3 Execution timed out 2062 ms 7824 KB Time limit exceeded
4 Halted 0 ms 0 KB -