답안 #92668

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
92668 2019-01-04T09:50:37 Z toloraia Money (IZhO17_money) C++14
100 / 100
1270 ms 216568 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e6;

int n;
int a[MAXN + 5];
int b[MAXN + 5];
int A[MAXN + 5][25], B[MAXN + 5][25];
int le[MAXN + 5];
int dp[MAXN + 5];
int BI[MAXN + 5];

int datvla (int l, int r){
    if (l > r)
        return n + 1;
    int x = 0, y = 1;
    while (y * 2 < r - l + 1){
        x++;
        y *= 2;
    }
    return min (A[l][x], B[r][x]);
}

int main()
{
    cin>>n;
    for (int i = 1; i <= n; i++)
        cin>>a[i];
    for (int i = 1; i <= MAXN; i++)
        b[i] = n + 1;
    for (int i = n; i >= 1; i--)
        b[a[i]] = i;
    for (int i = 1; i <= MAXN; i++){
        A[i][0] = b[i];
        B[i][0] = b[i];
    }
    for (int i = 1; i < 20; i++)
        for (int j = 1; j <= MAXN; j++){
            A[j][i] = A[j][i - 1];
            if (j + (1<<(i - 1)) <= MAXN)
                A[j][i] = min (A[j][i], A[j + (1<<(i - 1))][i - 1]);
            B[j][i] = B[j][i - 1];
            if (j - (1<<(i - 1)) >= 1)
                B[j][i] = min (B[j][i], B[j - (1<<(i - 1))][i - 1]);
        }
    le[1] = 1;
    for (int i = 2; i <= n; i++){
        le[i] = i;
        if (a[i] >= a[i - 1])
            le[i] = le[i - 1];
    }
    dp[1] = 1;
    for (int i = 2; i <= n; i++){
        int I = i;
        for (int j = 19; j >= 0; j--){
            if (I - (1<<j) < le[i])
                continue;
            if (datvla (a[I - (1<<j)] + 1, a[i] - 1) >= I - (1<<j))
                I -= (1<<j);
        }
        dp[i] = dp[I - 1] + 1;
    }
    cout<<dp[n]<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 680 ms 200052 KB Output is correct
2 Correct 711 ms 199972 KB Output is correct
3 Correct 785 ms 199972 KB Output is correct
4 Correct 781 ms 199972 KB Output is correct
5 Correct 787 ms 199984 KB Output is correct
6 Correct 836 ms 200056 KB Output is correct
7 Correct 829 ms 199928 KB Output is correct
8 Correct 815 ms 200056 KB Output is correct
9 Correct 826 ms 200076 KB Output is correct
10 Correct 808 ms 199976 KB Output is correct
11 Correct 782 ms 199976 KB Output is correct
12 Correct 797 ms 199976 KB Output is correct
13 Correct 789 ms 199972 KB Output is correct
14 Correct 787 ms 200056 KB Output is correct
15 Correct 791 ms 200108 KB Output is correct
16 Correct 773 ms 200064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 680 ms 200052 KB Output is correct
2 Correct 711 ms 199972 KB Output is correct
3 Correct 785 ms 199972 KB Output is correct
4 Correct 781 ms 199972 KB Output is correct
5 Correct 787 ms 199984 KB Output is correct
6 Correct 836 ms 200056 KB Output is correct
7 Correct 829 ms 199928 KB Output is correct
8 Correct 815 ms 200056 KB Output is correct
9 Correct 826 ms 200076 KB Output is correct
10 Correct 808 ms 199976 KB Output is correct
11 Correct 782 ms 199976 KB Output is correct
12 Correct 797 ms 199976 KB Output is correct
13 Correct 789 ms 199972 KB Output is correct
14 Correct 787 ms 200056 KB Output is correct
15 Correct 791 ms 200108 KB Output is correct
16 Correct 773 ms 200064 KB Output is correct
17 Correct 788 ms 200056 KB Output is correct
18 Correct 781 ms 200056 KB Output is correct
19 Correct 783 ms 200056 KB Output is correct
20 Correct 793 ms 199928 KB Output is correct
21 Correct 771 ms 199968 KB Output is correct
22 Correct 789 ms 200056 KB Output is correct
23 Correct 784 ms 200056 KB Output is correct
24 Correct 796 ms 200184 KB Output is correct
25 Correct 798 ms 199928 KB Output is correct
26 Correct 785 ms 200028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 680 ms 200052 KB Output is correct
2 Correct 711 ms 199972 KB Output is correct
3 Correct 785 ms 199972 KB Output is correct
4 Correct 781 ms 199972 KB Output is correct
5 Correct 787 ms 199984 KB Output is correct
6 Correct 836 ms 200056 KB Output is correct
7 Correct 829 ms 199928 KB Output is correct
8 Correct 815 ms 200056 KB Output is correct
9 Correct 826 ms 200076 KB Output is correct
10 Correct 808 ms 199976 KB Output is correct
11 Correct 782 ms 199976 KB Output is correct
12 Correct 797 ms 199976 KB Output is correct
13 Correct 789 ms 199972 KB Output is correct
14 Correct 787 ms 200056 KB Output is correct
15 Correct 791 ms 200108 KB Output is correct
16 Correct 773 ms 200064 KB Output is correct
17 Correct 788 ms 200056 KB Output is correct
18 Correct 781 ms 200056 KB Output is correct
19 Correct 783 ms 200056 KB Output is correct
20 Correct 793 ms 199928 KB Output is correct
21 Correct 771 ms 199968 KB Output is correct
22 Correct 789 ms 200056 KB Output is correct
23 Correct 784 ms 200056 KB Output is correct
24 Correct 796 ms 200184 KB Output is correct
25 Correct 798 ms 199928 KB Output is correct
26 Correct 785 ms 200028 KB Output is correct
27 Correct 780 ms 199932 KB Output is correct
28 Correct 771 ms 199980 KB Output is correct
29 Correct 781 ms 200056 KB Output is correct
30 Correct 781 ms 200056 KB Output is correct
31 Correct 788 ms 200056 KB Output is correct
32 Correct 812 ms 200056 KB Output is correct
33 Correct 674 ms 200100 KB Output is correct
34 Correct 752 ms 200056 KB Output is correct
35 Correct 723 ms 200056 KB Output is correct
36 Correct 714 ms 200056 KB Output is correct
37 Correct 738 ms 199992 KB Output is correct
38 Correct 717 ms 200056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 680 ms 200052 KB Output is correct
2 Correct 711 ms 199972 KB Output is correct
3 Correct 785 ms 199972 KB Output is correct
4 Correct 781 ms 199972 KB Output is correct
5 Correct 787 ms 199984 KB Output is correct
6 Correct 836 ms 200056 KB Output is correct
7 Correct 829 ms 199928 KB Output is correct
8 Correct 815 ms 200056 KB Output is correct
9 Correct 826 ms 200076 KB Output is correct
10 Correct 808 ms 199976 KB Output is correct
11 Correct 782 ms 199976 KB Output is correct
12 Correct 797 ms 199976 KB Output is correct
13 Correct 789 ms 199972 KB Output is correct
14 Correct 787 ms 200056 KB Output is correct
15 Correct 791 ms 200108 KB Output is correct
16 Correct 773 ms 200064 KB Output is correct
17 Correct 788 ms 200056 KB Output is correct
18 Correct 781 ms 200056 KB Output is correct
19 Correct 783 ms 200056 KB Output is correct
20 Correct 793 ms 199928 KB Output is correct
21 Correct 771 ms 199968 KB Output is correct
22 Correct 789 ms 200056 KB Output is correct
23 Correct 784 ms 200056 KB Output is correct
24 Correct 796 ms 200184 KB Output is correct
25 Correct 798 ms 199928 KB Output is correct
26 Correct 785 ms 200028 KB Output is correct
27 Correct 780 ms 199932 KB Output is correct
28 Correct 771 ms 199980 KB Output is correct
29 Correct 781 ms 200056 KB Output is correct
30 Correct 781 ms 200056 KB Output is correct
31 Correct 788 ms 200056 KB Output is correct
32 Correct 812 ms 200056 KB Output is correct
33 Correct 674 ms 200100 KB Output is correct
34 Correct 752 ms 200056 KB Output is correct
35 Correct 723 ms 200056 KB Output is correct
36 Correct 714 ms 200056 KB Output is correct
37 Correct 738 ms 199992 KB Output is correct
38 Correct 717 ms 200056 KB Output is correct
39 Correct 836 ms 208768 KB Output is correct
40 Correct 956 ms 213952 KB Output is correct
41 Correct 818 ms 206980 KB Output is correct
42 Correct 781 ms 206428 KB Output is correct
43 Correct 889 ms 204664 KB Output is correct
44 Correct 1085 ms 216396 KB Output is correct
45 Correct 1033 ms 216460 KB Output is correct
46 Correct 1065 ms 216504 KB Output is correct
47 Correct 1048 ms 216440 KB Output is correct
48 Correct 1122 ms 216524 KB Output is correct
49 Correct 1054 ms 216440 KB Output is correct
50 Correct 1127 ms 216312 KB Output is correct
51 Correct 1142 ms 216408 KB Output is correct
52 Correct 1084 ms 216312 KB Output is correct
53 Correct 1102 ms 216564 KB Output is correct
54 Correct 1192 ms 216432 KB Output is correct
55 Correct 1270 ms 216504 KB Output is correct
56 Correct 1266 ms 216444 KB Output is correct
57 Correct 1255 ms 216568 KB Output is correct
58 Correct 1136 ms 216424 KB Output is correct
59 Correct 1234 ms 216420 KB Output is correct
60 Correct 1249 ms 216412 KB Output is correct
61 Correct 1184 ms 216400 KB Output is correct
62 Correct 1193 ms 216524 KB Output is correct