# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
342824 | 2021-01-02T23:44:02 Z | Kalashnikov | K개의 묶음 (IZhO14_blocks) | C++17 | 1 ms | 512 KB |
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define all(a) a.begin() , a.end() #define F first #define S second using namespace std; using ll = long long; const int N = 2e5+5 , inf = 2e9 + 7; const ll INF = 1e18 , mod = 1e9+7 , P = 6547; int a[N]; double dp[N]; ll cnt[N]; int n , k; ll ans = 0; void check(double lam) { dp[1] = a[1] - lam; cnt[1] = 1; set<int> st; st.insert(a[1]); ans = 0; for(int i = 1; i < n; i ++) { dp[i+1] = min(max(dp[i] , a[i+1]-lam) , dp[i] + a[i+1] - lam); cnt[i+1] = cnt[i] + (max(dp[i] , a[i+1]-lam) > dp[i] + a[i+1] - lam); if(cnt[i] == cnt[i+1]) { st.insert(a[i+1]); } else { ans += *st.rbegin(); st.clear(); st.insert(a[i+1]); } } ans += *st.rbegin(); } void solve() { cin >> n >> k; for(int i = 1; i <= n; i ++) { cin >> a[i]; } for(int i = 0; i <= 1000; i ++) { check(i); //cout << dp[n]+cnt[n]*i << ' ' << cnt[n] << '\n'; } double l = 0 , r = 1e18; double lam; for(int i = 1; i <= 200; i ++) { double md = (l+r) / 2; check(md); if(cnt[n] <= k) { lam = md; l = md; } else { r = md; } } check(lam); cout << ans; } /* */ main() { file("blocks"); ios; int tt = 1; //cin >> tt; while(tt --) { solve(); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 512 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Incorrect | 1 ms | 364 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Incorrect | 1 ms | 364 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 512 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Incorrect | 1 ms | 364 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 512 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Incorrect | 1 ms | 364 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |