/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 6ms 5.066 MiB
#2 Wrong Answer 269ms 5.219 MiB
#3 Wrong Answer 210ms 5.129 MiB

Code

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

int const N = 2e5 + 10;
ll ans;
vector<ll> a(N), idx(N), dp(N);

void solve(int n){
  ll mn = 1e18;
  for (int i = 1; i < n + 10; i++){
    dp[i] = 1e18, idx[i] = i;
  }
  dp[1] = 0;
  idx[1] = idx[2] = idx[3] = 0;
  for (int i = 1; i <= n; i++){
    if (dp[i + 3] > dp[i] + a[i + 1] + a[i + 2]){
      dp[i + 3] = dp[i] + a[i + 1] + a[i + 2];
      idx[i + 3] = i;
    }
    ll cur = dp[i];
    for (int j = i; j <= i + 1; j++){
      cur += a[j];
      if (dp[j + 1] > cur){
        dp[j + 1] = cur;
        idx[j + 1] = idx[i];
      }
    }
  }
  int j = 0;
  for (int i = n + 1; i <= n + 3; i++){
    if (dp[i] < mn){
      mn = dp[i], j = idx[i];
    }
  } 
  while (j){
    a[j] = 0;
    j = idx[j];
  }
  ans += mn;
}
    
int main(){
  int t;
  cin >> t;
  while (t--){
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
      cin >> a[i];
    }
    for (int i = n + 1; i <= n + 7; i++) a[i] = 0;
    ans = 0;
    for (int i = 1; i <= 30; i++) solve(n);
    cout << ans << endl;
  }
}

Information

Submit By
Type
Submission
Problem
P1087 Face the monsters
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-18 08:51:14
Judged At
2024-11-11 02:53:27
Judged By
Score
5
Total Time
269ms
Peak Memory
5.219 MiB