답안 #263329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
263329 2020-08-13T15:40:31 Z FutymyClone Discharging (NOI20_discharging) C++14
47 / 100
1000 ms 91520 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;

int n, a[N], rmq[20][N];
long long dp[N];
deque <int> dq;

int query (int u, int v) {
    int k = log2(v - u + 1);
    return max(rmq[k][u], rmq[k][v - (1 << k) + 1]);
}

long long cost (int j, int i) {
    if (j > n || i > n || j > i) return 0;
    return dp[j] + 1LL * query(j + 1, i) * (n - j);
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], rmq[0][i] = a[i];
    for (int k = 1; k < 20; k++) {
        for (int i = 1; i + (1 << k) - 1 <= n; i++) {
            rmq[k][i] = max(rmq[k - 1][i], rmq[k - 1][i + (1 << (k - 1))]);
        }
    }

    memset(dp, 0x3f, sizeof(dp)); dp[0] = 0;
    dq.push_back(0);
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < dq.size(); j++) {
            dp[i] = min(dp[i], dp[dq[j]] + 1LL * query(dq[j] + 1, i) * (n - dq[j]));
        }
        //while (!dq.empty() && cost(dq.front(), i + 1) >= cost(i, i + 1)) dq.pop_front();
        while (!dq.empty() && dp[dq.back()] >= dp[i]) dq.pop_back();
        dq.push_back(i);
    }

    //for (int i = 1; i <= n; i++) cout << dp[i] << " ";
    //cout << "\n";
    cout << dp[n] << "\n";
    return 0;
}

Compilation message

Discharging.cpp: In function 'int main()':
Discharging.cpp:34:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for (int j = 0; j < dq.size(); j++) {
      |                         ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8192 KB Output is correct
2 Correct 5 ms 8192 KB Output is correct
3 Correct 5 ms 8192 KB Output is correct
4 Correct 5 ms 8192 KB Output is correct
5 Correct 5 ms 8192 KB Output is correct
6 Correct 6 ms 8192 KB Output is correct
7 Correct 5 ms 8192 KB Output is correct
8 Correct 5 ms 8192 KB Output is correct
9 Correct 5 ms 8192 KB Output is correct
10 Correct 5 ms 8224 KB Output is correct
11 Correct 5 ms 8192 KB Output is correct
12 Correct 5 ms 8192 KB Output is correct
13 Correct 5 ms 8192 KB Output is correct
14 Correct 5 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 8320 KB Output is correct
2 Correct 44 ms 8320 KB Output is correct
3 Correct 40 ms 8320 KB Output is correct
4 Correct 37 ms 8320 KB Output is correct
5 Correct 48 ms 8320 KB Output is correct
6 Correct 37 ms 8320 KB Output is correct
7 Correct 40 ms 8320 KB Output is correct
8 Correct 53 ms 8320 KB Output is correct
9 Correct 57 ms 8320 KB Output is correct
10 Correct 52 ms 8320 KB Output is correct
11 Correct 57 ms 8320 KB Output is correct
12 Correct 38 ms 8448 KB Output is correct
13 Correct 43 ms 8440 KB Output is correct
14 Correct 52 ms 8320 KB Output is correct
15 Correct 43 ms 8572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 8320 KB Output is correct
2 Correct 44 ms 8320 KB Output is correct
3 Correct 40 ms 8320 KB Output is correct
4 Correct 37 ms 8320 KB Output is correct
5 Correct 48 ms 8320 KB Output is correct
6 Correct 37 ms 8320 KB Output is correct
7 Correct 40 ms 8320 KB Output is correct
8 Correct 53 ms 8320 KB Output is correct
9 Correct 57 ms 8320 KB Output is correct
10 Correct 52 ms 8320 KB Output is correct
11 Correct 57 ms 8320 KB Output is correct
12 Correct 38 ms 8448 KB Output is correct
13 Correct 43 ms 8440 KB Output is correct
14 Correct 52 ms 8320 KB Output is correct
15 Correct 43 ms 8572 KB Output is correct
16 Execution timed out 1050 ms 91520 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 259 ms 86756 KB Output is correct
2 Correct 259 ms 86648 KB Output is correct
3 Correct 278 ms 86648 KB Output is correct
4 Correct 262 ms 86776 KB Output is correct
5 Correct 266 ms 86648 KB Output is correct
6 Correct 257 ms 86648 KB Output is correct
7 Correct 255 ms 86644 KB Output is correct
8 Correct 266 ms 86648 KB Output is correct
9 Correct 256 ms 86648 KB Output is correct
10 Correct 270 ms 86780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8192 KB Output is correct
2 Correct 5 ms 8192 KB Output is correct
3 Correct 5 ms 8192 KB Output is correct
4 Correct 5 ms 8192 KB Output is correct
5 Correct 5 ms 8192 KB Output is correct
6 Correct 6 ms 8192 KB Output is correct
7 Correct 5 ms 8192 KB Output is correct
8 Correct 5 ms 8192 KB Output is correct
9 Correct 5 ms 8192 KB Output is correct
10 Correct 5 ms 8224 KB Output is correct
11 Correct 5 ms 8192 KB Output is correct
12 Correct 5 ms 8192 KB Output is correct
13 Correct 5 ms 8192 KB Output is correct
14 Correct 5 ms 8192 KB Output is correct
15 Correct 59 ms 8320 KB Output is correct
16 Correct 44 ms 8320 KB Output is correct
17 Correct 40 ms 8320 KB Output is correct
18 Correct 37 ms 8320 KB Output is correct
19 Correct 48 ms 8320 KB Output is correct
20 Correct 37 ms 8320 KB Output is correct
21 Correct 40 ms 8320 KB Output is correct
22 Correct 53 ms 8320 KB Output is correct
23 Correct 57 ms 8320 KB Output is correct
24 Correct 52 ms 8320 KB Output is correct
25 Correct 57 ms 8320 KB Output is correct
26 Correct 38 ms 8448 KB Output is correct
27 Correct 43 ms 8440 KB Output is correct
28 Correct 52 ms 8320 KB Output is correct
29 Correct 43 ms 8572 KB Output is correct
30 Correct 6 ms 8320 KB Output is correct
31 Correct 6 ms 8320 KB Output is correct
32 Correct 6 ms 8320 KB Output is correct
33 Correct 6 ms 8320 KB Output is correct
34 Correct 6 ms 8320 KB Output is correct
35 Correct 6 ms 8320 KB Output is correct
36 Correct 6 ms 8320 KB Output is correct
37 Correct 7 ms 8320 KB Output is correct
38 Correct 6 ms 8320 KB Output is correct
39 Correct 6 ms 8320 KB Output is correct
40 Correct 6 ms 8320 KB Output is correct
41 Correct 7 ms 8320 KB Output is correct
42 Correct 6 ms 8320 KB Output is correct
43 Correct 37 ms 8320 KB Output is correct
44 Correct 6 ms 8448 KB Output is correct
45 Correct 6 ms 8320 KB Output is correct
46 Correct 7 ms 8320 KB Output is correct
47 Correct 7 ms 8320 KB Output is correct
48 Correct 7 ms 8320 KB Output is correct
49 Correct 6 ms 8320 KB Output is correct
50 Correct 6 ms 8320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8192 KB Output is correct
2 Correct 5 ms 8192 KB Output is correct
3 Correct 5 ms 8192 KB Output is correct
4 Correct 5 ms 8192 KB Output is correct
5 Correct 5 ms 8192 KB Output is correct
6 Correct 6 ms 8192 KB Output is correct
7 Correct 5 ms 8192 KB Output is correct
8 Correct 5 ms 8192 KB Output is correct
9 Correct 5 ms 8192 KB Output is correct
10 Correct 5 ms 8224 KB Output is correct
11 Correct 5 ms 8192 KB Output is correct
12 Correct 5 ms 8192 KB Output is correct
13 Correct 5 ms 8192 KB Output is correct
14 Correct 5 ms 8192 KB Output is correct
15 Correct 59 ms 8320 KB Output is correct
16 Correct 44 ms 8320 KB Output is correct
17 Correct 40 ms 8320 KB Output is correct
18 Correct 37 ms 8320 KB Output is correct
19 Correct 48 ms 8320 KB Output is correct
20 Correct 37 ms 8320 KB Output is correct
21 Correct 40 ms 8320 KB Output is correct
22 Correct 53 ms 8320 KB Output is correct
23 Correct 57 ms 8320 KB Output is correct
24 Correct 52 ms 8320 KB Output is correct
25 Correct 57 ms 8320 KB Output is correct
26 Correct 38 ms 8448 KB Output is correct
27 Correct 43 ms 8440 KB Output is correct
28 Correct 52 ms 8320 KB Output is correct
29 Correct 43 ms 8572 KB Output is correct
30 Execution timed out 1050 ms 91520 KB Time limit exceeded
31 Halted 0 ms 0 KB -