제출 #62812

#제출 시각아이디문제언어결과실행 시간메모리
62812win11905수열 (APIO14_sequence)C++11
0 / 100
34 ms9752 KiB
#include <bits/stdc++.h> using namespace std; #define long long long #define ll pair<long, long> #define x first #define y second const int N = 1e5+5; struct data { long m, c; int idx; data() { } data(long m, long c, int idx) : m(m), c(c), idx(idx) { } }; struct Convex_Hull { vector<data> vec; // m, c, idx int ptr = 0; bool del(data l0, data l1, data ln) { return (l1.c - l0.c) * (l0.m - ln.m) > (ln.c - l0.c) * (l0.m - l1.m); } void add(data d) { while(vec.size() >= 2 && del(vec[vec.size()-2], vec.back(), d)) vec.pop_back(); vec.emplace_back(d); } long get(int pos, long x) { return vec[pos].m * x + vec[pos].c; } ll query(long x) { if(ptr >= vec.size()) ptr = vec.size() - 1; while(ptr < vec.size()-1 && get(ptr, x) < get(ptr+1, x)) ptr++; return ll(get(ptr, x), vec[ptr].idx); } }; int n, k; long dp[2][N]; int s[201][N]; long pref[N]; int main() { scanf("%d %d", &n, &k); for(int i = 1; i <= n; ++i) scanf("%lld", pref+i), pref[i] += pref[i-1]; for(int i = 1; i <= k; ++i) { Convex_Hull hull; for(int j = 2; j <= n; ++j) { hull.add(data(pref[j-1], dp[~i&1][j-1] - pref[j-1] * pref[j-1], j-1)); ll ret = hull.query(pref[j]); dp[i&1][j] = ret.x, s[i][j] = ret.y; } } printf("%lld\n", dp[k&1][n]); for(int i = k, z = n; i; --i) printf("%d ", z = s[i][z]); }

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In member function 'std::pair<long long int, long long int> Convex_Hull::query(long long int)':
sequence.cpp:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(ptr >= vec.size()) ptr = vec.size() - 1;
            ~~~~^~~~~~~~~~~~~
sequence.cpp:31:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(ptr < vec.size()-1 && get(ptr, x) < get(ptr+1, x)) ptr++;
               ~~~~^~~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~
sequence.cpp:43:54: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; ++i) scanf("%lld", pref+i), pref[i] += pref[i-1];
                                 ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...