제출 #197945

#제출 시각아이디문제언어결과실행 시간메모리
197945songc수열 (APIO14_sequence)C++14
49 / 100
344 ms131076 KiB
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL,LL> pii; int N, K; LL S[101010]; int P[101010][220]; struct Line{ LL m, k; int id; }; bool popchk(Line a, Line b, Line c){ return ((__int128)b.k-c.k)*(b.m-a.m) <= ((__int128)a.k-b.k)*(c.m-b.m); } struct ConvHull{ vector<Line> V; int p; void push(Line l){ if (!V.empty() && V.back().m == l.m) return; while (V.size()>2 && popchk(V[V.size()-2], V.back(), l)){ V.pop_back(); if (V.size() <= p) p--; } V.push_back(l); } pii read(LL x){ while (p < V.size()-1 && V[p].m*x+V[p].k <= V[p+1].m*x+V[p+1].k) p++; return pii(V[p].m*x+V[p].k, V[p].id); } } CHT[220]; int main(){ scanf("%d %d", &N, &K); K++; for (int i=1; i<=N; i++){ scanf("%lld", &S[i]); S[i] += S[i-1]; } CHT[0].push((Line){0, 0, 0}); for (int i=1; i<=N; i++){ for (int j=1; j<=min(i, K); j++){ LL ret; tie(ret, P[i][j]) = CHT[j-1].read(S[i]); if (i == N && j == K) printf("%lld\n", ret); CHT[j].push((Line){S[i], ret-S[i]*S[i], i}); } } for (int i=K-1, p=P[N][K]; i; p=P[p][i], i--) printf("%d ", p); printf("\n"); return 0; }

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

sequence.cpp: In member function 'void ConvHull::push(Line)':
sequence.cpp:27:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (V.size() <= p) p--;
        ~~~~~~~~~^~~~
sequence.cpp: In member function 'pii ConvHull::read(LL)':
sequence.cpp:33:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (p < V.size()-1 && V[p].m*x+V[p].k <= V[p+1].m*x+V[p+1].k) p++;
          ~~^~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:40:7: 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:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &S[i]);
   ~~~~~^~~~~~~~~~~~~~~
#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...