답안 #1017162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017162 2024-07-09T04:59:29 Z Gray 수열 (APIO14_sequence) C++17
33 / 100
2000 ms 131072 KB
#include <algorithm>
#include <cassert>
#include <cstring>
#include <ios>
#include <iostream>
#include <map>
#include <vector>
#define ll long long
#define ull unsigned ll
#define ld long double
#define ff first
#define ss second
#define ln "\n"
#define pll pair<ll, ll>
using namespace std;

vector<ll> dep(100001), wr(201), pref(100001), vals(100001);
int link[100001][201];
void get(ll l, ll r, ll optl, ll optr, ll n, ll k){
	if (l>r) return;
	ll m = (l+r)/2;
	pll optm = {-1, -1};
	for (ll i=optl; i<=min(m-1, optr); i++){
		optm = max(optm, {dep[i]+(pref[m]-pref[i])*(pref[n]-pref[m]), i});
	}
	wr[m]=optm.ff;
	assert(optm.ss!=-1);
	link[m][k]=(int)(optm.ss);
	get(l, m-1, optl, optm.ss, n, k);
	get(m+1, r, optm.ss, optr, n, k);
}
void solve(){
	memset(link, 0, sizeof(link));
	ll n, k; cin >> n >> k;
	for (ll i=1; i<=n; i++){
		cin >> vals[i];
		pref[i]+=pref[i-1]+vals[i];
	}
	for (ll i=1; i<=k; i++){
		get(1, n, 0, n, n, i);
		wr.swap(dep);
	}
	pair<ll, ll> mx={-1, -1};
	for (ll i=0; i<n; i++) mx=max(mx, {dep[i], i});
	cout << mx.ff << ln;
	vector<ll> ans;
	for (ll i=k; i>=1; i--){
		ans.push_back(mx.ss);
		mx.ss=link[mx.ss][i];
	}
	for (ll i=k-1; i>=0; i--){
		cout << ans[i] << " ";
	}
	cout << ln;
}
// dp[i][k] = maxj(dp[j][k-1]+(pref[i]-pref[j])*(pref[n]-pref[i]));
// (dp[j][k-1]-pref[j]*pref[n])+pref[j]*pref[i];

int main(){
  	ios_base::sync_with_stdio(0);
  	cin.tie(nullptr);
  	ll t=1;
  	// cin >> t;
  	while (t--)solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 81496 KB contestant found the optimal answer: 108 == 108
2 Correct 33 ms 81236 KB contestant found the optimal answer: 999 == 999
3 Correct 34 ms 81232 KB contestant found the optimal answer: 0 == 0
4 Correct 32 ms 81236 KB contestant found the optimal answer: 1542524 == 1542524
5 Correct 35 ms 81236 KB contestant found the optimal answer: 4500000000 == 4500000000
6 Correct 39 ms 81236 KB contestant found the optimal answer: 1 == 1
7 Correct 32 ms 81320 KB contestant found the optimal answer: 1 == 1
8 Correct 33 ms 81236 KB contestant found the optimal answer: 1 == 1
9 Correct 32 ms 81352 KB contestant found the optimal answer: 100400096 == 100400096
10 Correct 34 ms 81232 KB contestant found the optimal answer: 900320000 == 900320000
11 Correct 40 ms 81236 KB contestant found the optimal answer: 3698080248 == 3698080248
12 Correct 34 ms 81244 KB contestant found the optimal answer: 3200320000 == 3200320000
13 Correct 34 ms 81232 KB contestant found the optimal answer: 140072 == 140072
14 Correct 33 ms 81232 KB contestant found the optimal answer: 376041456 == 376041456
15 Correct 33 ms 81244 KB contestant found the optimal answer: 805 == 805
16 Correct 32 ms 81240 KB contestant found the optimal answer: 900189994 == 900189994
17 Correct 32 ms 81388 KB contestant found the optimal answer: 999919994 == 999919994
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 81240 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 34 ms 81224 KB contestant found the optimal answer: 302460000 == 302460000
3 Correct 34 ms 81244 KB contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 41 ms 81436 KB contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 33 ms 81436 KB contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 33 ms 81232 KB contestant found the optimal answer: 933702 == 933702
7 Correct 35 ms 81268 KB contestant found the optimal answer: 25082842857 == 25082842857
8 Correct 34 ms 81232 KB contestant found the optimal answer: 687136 == 687136
9 Correct 33 ms 81236 KB contestant found the optimal answer: 27295930079 == 27295930079
10 Correct 35 ms 81236 KB contestant found the optimal answer: 29000419931 == 29000419931
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 81232 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 32 ms 81236 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 33 ms 81300 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 40 ms 81236 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 34 ms 81500 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Correct 33 ms 81496 KB contestant found the optimal answer: 107630884 == 107630884
7 Correct 34 ms 81412 KB contestant found the optimal answer: 475357671774 == 475357671774
8 Correct 32 ms 81336 KB contestant found the optimal answer: 193556962 == 193556962
9 Correct 32 ms 81232 KB contestant found the optimal answer: 482389919803 == 482389919803
10 Correct 32 ms 81236 KB contestant found the optimal answer: 490686959791 == 490686959791
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2276 ms 131072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2170 ms 131072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2333 ms 131072 KB Time limit exceeded
2 Halted 0 ms 0 KB -