/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 496.0 KiB
#2 Wrong Answer 73ms 672.0 KiB
#3 Wrong Answer 58ms 564.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using ll = long long;

int main() {
  FAST;
  
  int tc = 1, ti;
  cin >> tc;

  for (ti = 1; ti <= tc; ++ti) {
    ll n, i, j, t, sum, curr, ans;
    cin >> n;

    vector<ll> a(n), dp(n), to(n);
    for (i = 0; i < n; ++i) cin >> a[i];

    ans = 0;
    t = n; while (t--) {
      sum = accumulate(a.begin(), a.end(), 0ll);
      if (sum == 0) break;

      fill(dp.begin(), dp.end(), 0ll);
      fill(to.begin(), to.end(), n);
      for (i = n-3; i < n; ++i) dp[i] = a[i];
      for (i = n-4; i >= 0; --i) {
        for (j = i+3; j <= min(n-1, i+5); ++j) {
          curr = a[i] + dp[j];
          if (curr > dp[i]) {
            dp[i] = curr;
            to[i] = j;
          }
        }
      }

      vector<pair<ll,ll>> b;
      for (i = 0; i < 3; ++i) b.emplace_back(dp[i], i);
      sort(b.rbegin(), b.rend());

      i = b[0].second;
      while (i < n) {
        a[i] = 0;
        i = to[i];
      }
      ans += sum - b[0].first;
    }

    cout << ans << "\n";
  }

  return 0;
}

Information

Submit By
Type
Submission
Problem
P1087 Face the monsters
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 18:13:35
Judged At
2024-11-11 02:57:35
Judged By
Score
5
Total Time
73ms
Peak Memory
672.0 KiB