Submission #859663

# Submission time Handle Problem Language Result Execution time Memory
859663 2023-10-10T12:26:28 Z Tudy006 Peru (RMI20_peru) C++14
0 / 100
1 ms 2392 KB
#include <bits/stdc++.h>
//#include "peru.h"

using namespace std;

const int NMAX = 2500000;
const int MOD = 1e9 + 7;

long long dp[NMAX];

int solve( int n, int k, int* v ) {
    deque <int> dq;
    deque <pair<int, long long>> dq2;

    int ans = 0;
    for ( int i = 0; i < n; i ++ ) {
        while ( !dq.empty() && v[dq.back()] <= v[i] ) dq.pop_back();
        dq.push_back( i );

        if ( dq.front() <= i - k ) dq.pop_front();
        dp[i] = v[dq.front()] + ( i >= k ? dp[i - k] : 0 );

        while ( !dq2.empty() && v[dq2.back().first] <= v[i] ) dq2.pop_back();

        if ( dq.size() > 1 ) {
            long long aux = v[i] + dp[dq[dq.size() - 2]];

            while ( !dq2.empty() && dq2.back().second >= aux ) dq2.pop_back();

            dq2.push_back( { i, aux } );
            if ( dq2.front().first <= i - k ) dq2.pop_front();
            if ( dq2.front().first == dq.front() ) dq2.pop_front();

            if ( !dq2.empty() ) dp[i] = min( dp[i], dq2.front().second );
        }
//        cout << i << ": " << endl;
//        for ( auto x : dq ) cout << x << ' ';
//        cout << endl;
//        for ( auto p : dq2 ) cout << "( " << p.first << ", " << p.second << " )" << ' ';
//        cout << endl << "and the answer is: ";
//        cout << dp[i] << ' ';
//        cout << endl;
        ans = ( (long long)ans * 23 + dp[i] ) % MOD;
    }
//    cout << endl;
    dq.clear();
    dq2.clear();
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -