제출 #395790

#제출 시각아이디문제언어결과실행 시간메모리
395790kaplanbar수열 (APIO14_sequence)C++14
0 / 100
9 ms2084 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<ll> v(n); for(int i = 0; i < n; i++) cin >> v[i]; vector<ll> pre(n); for(int i = 0; i < n; i++) { pre[i] = v[i]; if(i) pre[i] += pre[i - 1]; } auto get_sum = [&](int l, int r) -> ll { ll ret = pre[r]; if(l) ret -= pre[l - 1]; return ret; }; ll s = get_sum(0, n - 1); ll ans = 0, cur = 0; vector<int> a; for(int i = 0; i < n; i++) { cur += v[i]; if(cur >= s / (k + 1)) { ans += cur * (s - cur); a.push_back(i + 1); cur = 0; } } if(a.size() == k + 1) { a.pop_back(); } else { ans += cur * (s - cur); } cout << ans / 2 << "\n"; for(int x : a) cout << x << " "; return 0; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:40:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |     if(a.size() == k + 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...