Submission #932333

#TimeUsernameProblemLanguageResultExecution timeMemory
932333alextodoranChorus (JOI23_chorus)C++17
61 / 100
7102 ms6408 KiB
/** _ _ __ _ _ _ _ _ _ |a ||t ||o d | |o | | __ _| | _ | __| _ | | __ |/_ | __ /__\ / _\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int N_MAX = 2000000; const ll INF = LLONG_MAX; const ld EPS = 1e-9; int N, K; int A[N_MAX + 2]; ld dp[N_MAX + 2]; int cnt[N_MAX + 2]; ll cost[N_MAX + 2]; pair <ld, int> f (int j) { return make_pair(dp[j] + cost[j + 1], cnt[j]); } ll solve (ld pen) { fill(cost + 1, cost + N + 1, 0); deque <int> rel; for (int i = 1; i <= N; i++) { for (int j = 1; j <= i; j++) { cost[j] += max(0, (A[i] - i + 1) - j); } pair <ld, int> mn = f(0); for (int j = 1; j <= i - 1; j++) { mn = min(mn, f(j)); } tie(dp[i], cnt[i]) = mn; dp[i] += pen; cnt[i]++; } return (ll) round(dp[N] - pen * K); } int main () { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(2); mt19937 rnd(time(0)); cin >> N >> K; // N = 10; K = rnd() % N + 1; string S; cin >> S; // for (int i = 0; i < N * 2; i++) { // S += (i < N ? 'A' : 'B'); // } // shuffle(S.begin(), S.end(), rnd); // cerr << N << " " << K << "\n"; // cerr << S << "\n"; for (int i = 0, j = 0; i < N * 2; i++) { if (S[i] == 'A') { A[++j] = i + 1; } } ld l = 0, r = LLONG_MAX; int iter = 150; while (iter--) { ld mid = (l + r) / 2; solve(mid); if (cnt[N] <= K) { r = mid; } else { l = mid + EPS; } } cout << solve(l) << "\n"; return 0; }
#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...