이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Sasayego! Sasayego! Shinzou wo Sasageyo!
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bitset>
#include <ctime>
#define debug(x) cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
const int maxN = 1e5 + 5;
const int maxK = 2e2 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
int level, eren[maxK][maxN];
ll a[maxN], arumin[2][maxN];
vector <int> vec;
ll cost(int lt, int rt){
ll tmp = a[rt] - a[lt - 1];
return tmp * tmp;
}
void DC(int l, int r, int s, int e){
if (r < l)
return;
int md = (l + r) >> 1;
bool b = level % 2;
for (int i = s; i <= min(md, e); i++)
if (arumin[b][md] >= arumin[!b][i - 1] + cost(i, md)){
arumin[b][md] = arumin[!b][i - 1] + cost(i, md);
eren[level][md] = i;
}
DC(l, md - 1, s, eren[level][md]);
DC(md + 1, r, eren[level][md], e);
return;
}
int main(){
time_t START = clock();
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
memset(arumin, 63, sizeof arumin);
arumin[0][0] = 0;
int n, k; scanf("%d%d", &n, &k); k++;
for (int i = 1; i <= n; i++){
scanf("%lld", a + i);
a[i] += a[i - 1];
}
for (level = 1; level <= k; level++)
DC(level, n, level, n);
printf("%lld\n", (a[n] * a[n] - arumin[k % 2][n]) >> 1);
while (k > 1){
vec.push_back(eren[k][n] - 1);
n = eren[k][n] - 1;
k--;
}
reverse(vec.begin(), vec.end());
for (int x : vec)
printf("%d ", x);
printf("\n");
time_t FINISH = clock();
cerr << "Execution time: " << (ld)(FINISH - START) / CLOCKS_PER_SEC * 1000.0 << " milliseconds.\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int main()':
sequence.cpp:59:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int n, k; scanf("%d%d", &n, &k); k++;
~~~~~^~~~~~~~~~~~~~~~
sequence.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", a + i);
~~~~~^~~~~~~~~~~~~~~
# | 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... |