제출 #1158403

#제출 시각아이디문제언어결과실행 시간메모리
1158403arkanefury수열 (APIO14_sequence)C++20
50 / 100
85 ms12872 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define in insert #define lb lower_bound #define F first #define S second #define sz size() #define int long long #define all(v) v.begin(),v.end() #define FOR1(x, n) for(int j = x; j <= n; j ++) #define FOR(x, n, m, d) for(int x = n; x <= m; x += d) #define FORR(x, n, m, d) for(int x = n; x >= m; x -= d) #define nikita ios_base::sync_with_stdio(0), cin.tie(0); const int N = 1000+5; int a[N], b[N], pref[N], dp[N][N]; int n,m,k,sum=0,x,y, ans, r, cnt, l, mod = 1e9+7, inf = -1e18; string s, str; bool used[N]; pair<int, int> mt[N][N]; void solve(){ cin >> n >> m; FOR(i, 1, n, 1)cin >> a[i], pref[i] = pref[i-1] + a[i]; FOR(i, 1, n, 1){ FOR(j, 1, m, 1)dp[i][j] = inf; } x = y = 0; FOR(i, 1, m, 1){ FOR(j, 1, n-1, 1){ FORR( ok, j-1, i-1, 1 ){ cnt = dp[ok][i-1] + (pref[n] - pref[j]) * (pref[j] - pref[ok]); if(dp[j][i] < cnt){ dp[j][i] = cnt, mt[j][i] = { ok, i-1 }; if(ans < dp[j][i]) x = j, y = i; } } ans = max(ans, dp[j][i]); } } cout << ans << '\n'; int ko = 0; while(x * y > 0){ cout << x << ' '; used[x] = 1, ko ++; pair<int, int>prev = mt[x][y]; x = prev.F, y = prev.S; } FOR(i, 1, n-1, 1)if(ko < m && !used[i])cout << i << ' ', ko ++; } signed main(){ nikita int tt = 1; if(!tt)cin >> tt; FOR(i, 1, tt, 1)solve(); }
#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...