/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Wrong Answer 100ms 644.0 KiB
#3 Wrong Answer 81ms 552.0 KiB
#4 Wrong Answer 82ms 580.0 KiB
#5 Wrong Answer 82ms 1012.0 KiB
#6 Wrong Answer 83ms 5.117 MiB
#7 Wrong Answer 83ms 5.066 MiB
#8 Wrong Answer 79ms 5.109 MiB
#9 Wrong Answer 73ms 5.117 MiB
#10 Wrong Answer 67ms 5.121 MiB
#11 Wrong Answer 61ms 5.113 MiB
#12 Wrong Answer 54ms 5.121 MiB
#13 Wrong Answer 47ms 5.113 MiB
#14 Wrong Answer 40ms 5.117 MiB
#15 Wrong Answer 35ms 5.117 MiB
#16 Accepted 34ms 5.113 MiB
#17 Wrong Answer 26ms 1.945 MiB
#18 Wrong Answer 18ms 608.0 KiB
#19 Accepted 24ms 756.0 KiB
#20 Accepted 90ms 5.117 MiB

Code

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

int main(){
  int t;
  cin >> t;
  while (t--){
    ll n, ans = 0;
    cin >> n;
    vector<ll> a(n + 10), vis(n + 10), dp(n + 10, 1e18);
    for (int i = 1; i <= n; i++){
      cin >> a[i];
    }
    dp[1] = 0, dp[2] = a[1], dp[3] = a[1] + a[2];
    for (int i = 1; i <= n; i++){
      dp[i + 3] = min(dp[i + 3], dp[i] + a[i + 1] + a[i + 2]);
    }
    ll j, mn = 1e18;
    for (int i = n + 1; i <= n + 3; i++){
      if (dp[i] < mn){
        mn = dp[i], j = i;
      }
    } //cout<<mn<<endl;
    ans += mn;
    mn = 1e18;
    for (int i = j; i > 0; i -= 3){
      vis[i] = 1, a[i] = 0;
    } //for(int i=1;i<=n;i++)cout<<a[i]<<" ";cout<<endl;
    dp[2] = a[1], dp[3] = a[1] + a[2];
    for (int i = 4; i <= n + 3; i++) dp[i] = 1e18;
    for (int i = 1; i <= n; i++){
      dp[i + 3] = min(dp[i + 3], dp[i] + a[i + 1] + a[i + 2]);
    }
    for (int i = n + 1; i <= n + 3; i++){
      if (!vis[i] && dp[i] < mn){
        mn = dp[i];
      }
    } //cout<<mn<<endl;
    cout << ans + mn << endl;
  }
}

Information

Submit By
Type
Submission
Problem
P1087 Face the monsters
Contest
Brain Booster #5
Language
C++17 (G++ 13.2.0)
Submit At
2024-09-05 17:29:34
Judged At
2024-10-03 13:03:39
Judged By
Score
20
Total Time
100ms
Peak Memory
5.121 MiB