답안 #641407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641407 2022-09-16T15:45:04 Z Alexandruabcde Peru (RMI20_peru) C++14
100 / 100
553 ms 78532 KB
#include "peru.h"
#include <iostream>
#include <deque>
#include <queue>
#include <vector>

using namespace std;

constexpr int NMAX = 2500005;
constexpr int MOD = 1e9 + 7;
typedef long long LL;
constexpr LL INF = 1LL * 1e16;
typedef pair <LL, int> PLI;

int ans = 0;
LL dp[NMAX];
LL val[NMAX];

int solve(int n, int k, int* v){
    deque <int> D;
    priority_queue <PLI, vector<PLI>, greater<PLI> > H;
    for (int i = 0; i < n; ++ i ) {
        dp[i] = INF;

        while (!D.empty() && v[D.back()] <= v[i]) {
            val[D.back()] = -1;

            D.pop_back();
        }

        while (!D.empty() && D.front() <= i - k) {
            val[D.front()] = -1;

            D.pop_front();
        }

        D.push_back(i);

        if (!D.empty()) {
            val[D.front()] = 1LL * v[D.front()] + (i - k < 0 ? 0 : dp[i - k]);

            H.push({val[D.front()], D.front()});
        }

        if (D.size() >= 2) {
            val[D.back()] = 1LL * v[D.back()] + dp[D[D.size()-2]];

            H.push({val[D.back()], D.back()});
        }
        else {
            val[D.back()] = 1LL * v[D.back()] + (i - k < 0 ? 0 : dp[i - k]);

            H.push({val[D.back()], D.back()});
        }

        while (!H.empty() && val[H.top().second] != H.top().first)
            H.pop();

        if (!H.empty()) dp[i] = H.top().first;
        else dp[i] = 1LL * v[D.front()] + (i - k < 0 ? 0 : dp[i - k]);
    }

    for (int i = 0; i < n; ++ i )
        ans = (23LL * ans + dp[i] % MOD) % MOD;

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 78 ms 12448 KB Output is correct
16 Correct 79 ms 12368 KB Output is correct
17 Correct 82 ms 12356 KB Output is correct
18 Correct 97 ms 12364 KB Output is correct
19 Correct 92 ms 12272 KB Output is correct
20 Correct 92 ms 12408 KB Output is correct
21 Correct 88 ms 12360 KB Output is correct
22 Correct 81 ms 12480 KB Output is correct
23 Correct 100 ms 12568 KB Output is correct
24 Correct 83 ms 12496 KB Output is correct
25 Correct 79 ms 12400 KB Output is correct
26 Correct 78 ms 12364 KB Output is correct
27 Correct 79 ms 12372 KB Output is correct
28 Correct 88 ms 12508 KB Output is correct
29 Correct 83 ms 12648 KB Output is correct
30 Correct 80 ms 12416 KB Output is correct
31 Correct 76 ms 12296 KB Output is correct
32 Correct 82 ms 12552 KB Output is correct
33 Correct 77 ms 12388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 12448 KB Output is correct
2 Correct 79 ms 12368 KB Output is correct
3 Correct 82 ms 12356 KB Output is correct
4 Correct 97 ms 12364 KB Output is correct
5 Correct 92 ms 12272 KB Output is correct
6 Correct 92 ms 12408 KB Output is correct
7 Correct 88 ms 12360 KB Output is correct
8 Correct 81 ms 12480 KB Output is correct
9 Correct 100 ms 12568 KB Output is correct
10 Correct 83 ms 12496 KB Output is correct
11 Correct 79 ms 12400 KB Output is correct
12 Correct 78 ms 12364 KB Output is correct
13 Correct 79 ms 12372 KB Output is correct
14 Correct 88 ms 12508 KB Output is correct
15 Correct 83 ms 12648 KB Output is correct
16 Correct 80 ms 12416 KB Output is correct
17 Correct 76 ms 12296 KB Output is correct
18 Correct 82 ms 12552 KB Output is correct
19 Correct 77 ms 12388 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 512 ms 53972 KB Output is correct
35 Correct 513 ms 73280 KB Output is correct
36 Correct 511 ms 73236 KB Output is correct
37 Correct 520 ms 73272 KB Output is correct
38 Correct 520 ms 73424 KB Output is correct
39 Correct 523 ms 73412 KB Output is correct
40 Correct 521 ms 73280 KB Output is correct
41 Correct 523 ms 73188 KB Output is correct
42 Correct 524 ms 73480 KB Output is correct
43 Correct 213 ms 29868 KB Output is correct
44 Correct 356 ms 45068 KB Output is correct
45 Correct 347 ms 45064 KB Output is correct
46 Correct 348 ms 45164 KB Output is correct
47 Correct 533 ms 75420 KB Output is correct
48 Correct 532 ms 75568 KB Output is correct
49 Correct 542 ms 75824 KB Output is correct
50 Correct 527 ms 76384 KB Output is correct
51 Correct 532 ms 76492 KB Output is correct
52 Correct 553 ms 78532 KB Output is correct
53 Correct 550 ms 76972 KB Output is correct
54 Correct 516 ms 73188 KB Output is correct
55 Correct 495 ms 73068 KB Output is correct
56 Correct 490 ms 73152 KB Output is correct
57 Correct 503 ms 73024 KB Output is correct
58 Correct 503 ms 73276 KB Output is correct
59 Correct 529 ms 73132 KB Output is correct
60 Correct 516 ms 73124 KB Output is correct
61 Correct 542 ms 75660 KB Output is correct
62 Correct 536 ms 75580 KB Output is correct
63 Correct 541 ms 75512 KB Output is correct