이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define ind(a) scanf("%d", &a)
#define inlld(a) scanf("%lld", &a)
#define ind2(a, b) scanf("%d%d", &a, &b)
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
#define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
using namespace std;
const int N=1e3+5;
const int MOD=1e9+7;
typedef long long ll;
typedef long double ld;
ll arr[N], n, k, dp[N][205], pref[N], nex[N][205];
int main()
{
inlld2(n, k);
for(ll a=1; a<=n; a++)
{
inlld(arr[a]);
pref[a]=pref[a-1]+arr[a];
}
for(ll a=1; a<=n; a++)
for(ll b=1; b<=k; b++)
dp[a][b]=-1e18;
for(ll b=1; b<=k; b++)
for(ll a=1; a<=n; a++)
for(ll c=1; c<a; c++)
{
// dp[a][b]=max(dp[a][b], dp[c][b-1]+(pref[a]-pref[c])*pref[c]);
if(dp[c][b-1]+(pref[a]-pref[c])*pref[c]>dp[a][b])
{
dp[a][b]=dp[c][b-1]+(pref[a]-pref[c])*pref[c];
nex[a][b]=c;
}
}
printf("%lld\n", dp[n][k]);
ll i=n, j=k;
vector<ll>ans;
while(j--)
{
// printf("%lld\n", nex[i][j]+1);
ans.pb(nex[i][j]+1);
i=nex[i][j];
}
for(ll a=ans.size()-1; a>=0; a--)
printf("%lld ", ans[a]);
printf("\n");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int main()':
sequence.cpp:8:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
~~~~~^~~~~~~~~~~~~~~~~~~~
sequence.cpp:24:5: note: in expansion of macro 'inlld2'
inlld2(n, k);
^~~~~~
sequence.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define inlld(a) scanf("%lld", &a)
~~~~~^~~~~~~~~~~~
sequence.cpp:27:9: note: in expansion of macro 'inlld'
inlld(arr[a]);
^~~~~
# | 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... |