답안 #635764

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635764 2022-08-26T19:16:47 Z martin_nedev Peru (RMI20_peru) C++14
18 / 100
600 ms 39500 KB
#include "peru.h"

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

#ifdef __LOCALTEST
    #include "grader.cpp"
#endif // __LOCALTEST

//first subtask
const int MAXLOG = 20;
const int MAXN = 400000;
const int64_t inf = 1e17;
const int64_t mod = 1e9+7;

struct RangeMaximumQuery
{
    int n;
    int log[MAXN+10];
    int sparseTable[MAXLOG+2][MAXN+10];

    RangeMaximumQuery(int n)
    {
        //precompute log array
        //!log[i] gives the value of log2(i) rounded down

        this->n = n;

        log[1] = 0;
        for (int i = 2; i <= n; i++)
            log[i] = log[i>>1] + 1;


    }

    void Build(int *arr)
    {
        //construct sparse table

        for (int i = 0; i < n; i++)
            sparseTable[0][i] = arr[i];

        for (int lg = 1; lg <= MAXLOG; lg++)
        {
            for (int i = 0; i < n; i++)
            {
                int jump = (1<<(lg-1));

                if (i+jump >= n)
                    sparseTable[lg][i] = sparseTable[lg-1][i];

                else
                    sparseTable[lg][i] = max(sparseTable[lg-1][i], sparseTable[lg-1][i+jump]);
            }
        }
    }

    int Query(int leftQ, int rightQ)
    {
        //answering query
        return max(sparseTable[log[rightQ-leftQ+1]][leftQ],
                   sparseTable[log[rightQ-leftQ+1]][rightQ-(1<<log[rightQ-leftQ+1])+1]);
    }

};

int evaluateAnswer(const int n, int64_t *arr)
{
    int64_t ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans = (ans*23 + arr[i])%mod;
    }

    return ans;
}

int64_t dp[MAXN+10];
int solve(int n, int k, int* v)
{
    RangeMaximumQuery *rmq = new RangeMaximumQuery(n);
    rmq->Build(v);

    for (int i = 0; i < n; i++)
        dp[i] = inf;

    dp[0] = v[0];

    for (int i = 1; i < n; i++)
    {
        int down = max(0, i-k+1);
        for (int j = i; j >= down; j--)
        {
            /*if (j == 0)
                dp[i] = max(dp[i], int64_t(rmq->Query(j, i)));*/

            //else
                dp[i] = min(dp[i], dp[j-1]+int64_t(rmq->Query(j, i)));
        }

        //cout << dp[i] << endl;

    }

    //cout << evaluateAnswer(n, dp) << endl;

    int ans = evaluateAnswer(n, dp);
    return ans;

}


/*
8 3
3 2 9 8 7 11 3 4

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Execution timed out 1092 ms 39500 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 39500 KB Time limit exceeded
2 Halted 0 ms 0 KB -