/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 7ms 6.562 MiB
#2 Wrong Answer 126ms 6.711 MiB
#3 Wrong Answer 107ms 6.664 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), vis(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] = 0;
  for (int i = 1; i <= n; i++){
    if (dp[i + 1] > dp[i] + a[i]){
      dp[i + 1] = dp[i] + a[i];
      idx[i + 1] = idx[i];
    }
    if (dp[i + 2] > dp[i] + a[i] + a[i + 1]){
      dp[i + 2] = dp[i] + a[i] + a[i + 1];
      idx[i + 2] = idx[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;
    }
  }
  int j = 0;
  for (int i = n + 1; i <= n + 3; i++){
    if (!vis[i] && dp[i] < mn){
      mn = dp[i], j = i;
    }
  } 
  for (int i = j; i > 0; ){
    vis[i] = 1, a[i] = 0;
    i = idx[i];
  }
  if (j > 0) ans += mn;
}
    

int main(){
  int t;
  cin >> t;
  while (t--){
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
      cin >> a[i];
      vis[i] = 0;
    }
    vis[n + 1] = vis[n + 2] = vis[n + 3] = 0;
    ans = 0;
    solve(n);
    solve(n);
    solve(n);
    solve(n);
    solve(n);
    solve(n);
    cout << ans << endl;
  }
}

Information

Submit By
Type
Submission
Problem
P1087 Face the monsters
Language
C++17 (G++ 13.2.0)
Submit At
2024-09-05 18:15:14
Judged At
2024-11-11 02:57:34
Judged By
Score
5
Total Time
126ms
Peak Memory
6.711 MiB