제출 #395788

#제출 시각아이디문제언어결과실행 시간메모리
395788kaplanbar수열 (APIO14_sequence)C++14
0 / 100
9 ms1868 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; } } assert(a.size() == k + 1); a.pop_back(); cout << ans / 2 << "\n"; for(int x : a) cout << x << " "; return 0; }

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

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from sequence.cpp:1:
sequence.cpp: In function 'int main()':
sequence.cpp:40:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |     assert(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...