/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 2.324 MiB
#2 Wrong Answer 44ms 664.0 KiB
#3 Wrong Answer 42ms 584.0 KiB
#4 Wrong Answer 43ms 2.57 MiB
#5 Wrong Answer 43ms 2.82 MiB
#6 Wrong Answer 46ms 5.566 MiB
#7 Wrong Answer 47ms 5.418 MiB
#8 Wrong Answer 45ms 5.449 MiB
#9 Wrong Answer 40ms 5.645 MiB
#10 Wrong Answer 40ms 5.574 MiB
#11 Wrong Answer 38ms 5.59 MiB
#12 Wrong Answer 37ms 5.402 MiB
#13 Wrong Answer 33ms 5.641 MiB
#14 Wrong Answer 33ms 5.418 MiB
#15 Wrong Answer 31ms 5.398 MiB
#16 Accepted 29ms 5.57 MiB
#17 Wrong Answer 16ms 2.117 MiB
#18 Wrong Answer 11ms 2.695 MiB
#19 Accepted 13ms 680.0 KiB
#20 Accepted 48ms 5.559 MiB

Code

/*For today, you happen to be the defeated. But what will you become tomorrow?*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int long long int 
#define dbg if(debugg)
#define F first 
#define S second 

bool debugg = false;

template <typename T>
using order_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

template <typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());  
const int N = 200005;
int arr[N], dp[N], n;

void reset(int n)
{
    for(int i = 0; i <= n; i ++) dp[i] = -1;
}

int magic(int pos)
{
    if(pos > n) return 0;
    int &ans = dp[pos];
    if(~ans) return ans;
    ans = max(magic(pos + 1), arr[pos] + magic(pos + 3));
    return ans; 
}

void build(int pos)
{
    if(pos > n) return;
    if(magic(pos + 1) >= arr[pos] + magic(pos + 3)){
        build(pos + 1);
    }
    else{
        arr[pos] = 0;
        build(pos + 3);
    }
}
void solve()
{
    int sum = 0, ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> arr[i];
        sum += arr[i];
    }

    reset(n);
    sum -= magic(1);
    ans += sum;
    build(1);
    
    reset(n);
    sum -= magic(1);
    ans += sum;
    cout << ans << '\n';
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
        
    int t = 1;
    cin >> t;
    
    while(t--){
        solve();
    }

    return 0;
}

Information

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