Submission #892178

# Submission time Handle Problem Language Result Execution time Memory
892178 2023-12-25T03:25:32 Z Peter2017 Financial Report (JOI21_financial) C++14
65 / 100
646 ms 198336 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pill pair<int,ll>
#define mem(a, b) memset(a, b, sizeof(a))
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define name "test"

using namespace std;

const int N = 3e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18 + 69;

template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;}
template <typename T1, typename T2> bool mini(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;}

int n;
int k;
int D;
int a[N];
int f[(int)7e3 + 2][(int)7e3 + 2];
deque <int> dq[(int)7e3 + 2];
vector <int> value;

void load(){
    cin.tie(0)->sync_with_stdio(0);
    if (fopen(name".inp", "r")){
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }
}

void input(){
    cin >> n >> D;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
}

void compress(){
    for (int i = 1; i <= n; i++)
        value.push_back(a[i]);
    sort(value.begin(), value.end());
    value.erase(unique(value.begin(), value.end()), value.end());
    for (int i = 1; i <= n; i++)
        a[i] = lower_bound(value.begin(), value.end(), a[i]) - value.begin() + 1;
    k = (int)value.size();
}

namespace subtask3{
    void solve(){
        mem(f, -0x3f);
        for (int i = 1; i <= n; i++){
            f[i][a[i]] = 1;
            for (int j = 1; j <= k; j++){
                if (dq[j].size() && dq[j].front() < i - D) dq[j].pop_front();
                if (dq[j].size()) maxi(f[i][max(a[i], j)], f[dq[j].front()][j] + (j < a[i]));
            }
            for (int j = 1; j <= k; j++){
                while (dq[j].size() && f[dq[j].back()][j] <= f[i][j])
                    dq[j].pop_back();
                dq[j].push_back(i);
            }
        }
        int ans = 0;
        for (int i = 1; i <= k; i++)
            maxi(ans, f[n][i]);
        cout << ans;
    }
}

namespace subtask4{
    stack <int> st;
    void solve(){
        st.push(n);
        int ans = 1;
        for (int i = n - 1; i >= 1; i--){
            while (st.size() && a[st.top()] <= a[i]) st.pop();
            st.push(i);
            maxi(ans, st.size());
        }
        cout << ans;
    }
}

namespace subtask5{
    int b[N];
    void solve(){
        mem(b, 0x3f);
//        f[0] = -mod;
        int ans = 0;
        for (int i = 1; i <= n; i++){
            int id = lower_bound(b + 1, b + n + 1, a[i]) - b;
//            if (i == n) cout << id;
            b[id] = a[i];
            maxi(ans, id);
        }
        cout << ans;
    }
}

int main(){
    load();
    input();
    compress();
    if (n <= (int)7e3){
        subtask3::solve();
        return 0;
    }
    if (D == 1){
        subtask4::solve();
        return 0;
    }
    subtask5::solve();
}

Compilation message

Main.cpp: In instantiation of 'bool maxi(T1&, T2) [with T1 = int; T2 = long unsigned int]':
Main.cpp:85:32:   required from here
Main.cpp:19:66: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
   19 | template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;}
      |                                                                ~~^~~
Main.cpp: In function 'void load()':
Main.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 54 ms 197968 KB Output is correct
2 Correct 25 ms 197968 KB Output is correct
3 Correct 27 ms 197976 KB Output is correct
4 Correct 25 ms 197936 KB Output is correct
5 Correct 26 ms 197968 KB Output is correct
6 Correct 24 ms 197972 KB Output is correct
7 Correct 25 ms 197964 KB Output is correct
8 Correct 25 ms 197972 KB Output is correct
9 Correct 24 ms 197980 KB Output is correct
10 Correct 25 ms 197880 KB Output is correct
11 Correct 25 ms 198024 KB Output is correct
12 Correct 24 ms 197940 KB Output is correct
13 Correct 24 ms 197980 KB Output is correct
14 Correct 26 ms 198048 KB Output is correct
15 Correct 25 ms 197980 KB Output is correct
16 Correct 25 ms 197968 KB Output is correct
17 Correct 24 ms 197972 KB Output is correct
18 Correct 24 ms 197988 KB Output is correct
19 Correct 24 ms 197936 KB Output is correct
20 Correct 24 ms 197972 KB Output is correct
21 Correct 24 ms 197968 KB Output is correct
22 Correct 24 ms 197972 KB Output is correct
23 Correct 24 ms 197972 KB Output is correct
24 Correct 25 ms 197968 KB Output is correct
25 Correct 25 ms 197980 KB Output is correct
26 Correct 24 ms 197968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 197968 KB Output is correct
2 Correct 25 ms 197968 KB Output is correct
3 Correct 27 ms 197976 KB Output is correct
4 Correct 25 ms 197936 KB Output is correct
5 Correct 26 ms 197968 KB Output is correct
6 Correct 24 ms 197972 KB Output is correct
7 Correct 25 ms 197964 KB Output is correct
8 Correct 25 ms 197972 KB Output is correct
9 Correct 24 ms 197980 KB Output is correct
10 Correct 25 ms 197880 KB Output is correct
11 Correct 25 ms 198024 KB Output is correct
12 Correct 24 ms 197940 KB Output is correct
13 Correct 24 ms 197980 KB Output is correct
14 Correct 26 ms 198048 KB Output is correct
15 Correct 25 ms 197980 KB Output is correct
16 Correct 25 ms 197968 KB Output is correct
17 Correct 24 ms 197972 KB Output is correct
18 Correct 24 ms 197988 KB Output is correct
19 Correct 24 ms 197936 KB Output is correct
20 Correct 24 ms 197972 KB Output is correct
21 Correct 24 ms 197968 KB Output is correct
22 Correct 24 ms 197972 KB Output is correct
23 Correct 24 ms 197972 KB Output is correct
24 Correct 25 ms 197968 KB Output is correct
25 Correct 25 ms 197980 KB Output is correct
26 Correct 24 ms 197968 KB Output is correct
27 Correct 26 ms 197972 KB Output is correct
28 Correct 26 ms 197976 KB Output is correct
29 Correct 25 ms 197936 KB Output is correct
30 Correct 26 ms 197972 KB Output is correct
31 Correct 24 ms 197972 KB Output is correct
32 Correct 26 ms 197976 KB Output is correct
33 Correct 27 ms 197908 KB Output is correct
34 Correct 26 ms 197976 KB Output is correct
35 Correct 31 ms 197980 KB Output is correct
36 Correct 27 ms 197980 KB Output is correct
37 Correct 26 ms 197876 KB Output is correct
38 Correct 26 ms 197972 KB Output is correct
39 Correct 27 ms 197908 KB Output is correct
40 Correct 26 ms 197940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 197968 KB Output is correct
2 Correct 25 ms 197968 KB Output is correct
3 Correct 27 ms 197976 KB Output is correct
4 Correct 25 ms 197936 KB Output is correct
5 Correct 26 ms 197968 KB Output is correct
6 Correct 24 ms 197972 KB Output is correct
7 Correct 25 ms 197964 KB Output is correct
8 Correct 25 ms 197972 KB Output is correct
9 Correct 24 ms 197980 KB Output is correct
10 Correct 25 ms 197880 KB Output is correct
11 Correct 25 ms 198024 KB Output is correct
12 Correct 24 ms 197940 KB Output is correct
13 Correct 24 ms 197980 KB Output is correct
14 Correct 26 ms 198048 KB Output is correct
15 Correct 25 ms 197980 KB Output is correct
16 Correct 25 ms 197968 KB Output is correct
17 Correct 24 ms 197972 KB Output is correct
18 Correct 24 ms 197988 KB Output is correct
19 Correct 24 ms 197936 KB Output is correct
20 Correct 24 ms 197972 KB Output is correct
21 Correct 24 ms 197968 KB Output is correct
22 Correct 24 ms 197972 KB Output is correct
23 Correct 24 ms 197972 KB Output is correct
24 Correct 25 ms 197968 KB Output is correct
25 Correct 25 ms 197980 KB Output is correct
26 Correct 24 ms 197968 KB Output is correct
27 Correct 26 ms 197972 KB Output is correct
28 Correct 26 ms 197976 KB Output is correct
29 Correct 25 ms 197936 KB Output is correct
30 Correct 26 ms 197972 KB Output is correct
31 Correct 24 ms 197972 KB Output is correct
32 Correct 26 ms 197976 KB Output is correct
33 Correct 27 ms 197908 KB Output is correct
34 Correct 26 ms 197976 KB Output is correct
35 Correct 31 ms 197980 KB Output is correct
36 Correct 27 ms 197980 KB Output is correct
37 Correct 26 ms 197876 KB Output is correct
38 Correct 26 ms 197972 KB Output is correct
39 Correct 27 ms 197908 KB Output is correct
40 Correct 26 ms 197940 KB Output is correct
41 Correct 132 ms 198204 KB Output is correct
42 Correct 610 ms 198336 KB Output is correct
43 Correct 29 ms 197980 KB Output is correct
44 Correct 230 ms 198184 KB Output is correct
45 Correct 245 ms 198192 KB Output is correct
46 Correct 646 ms 198220 KB Output is correct
47 Correct 513 ms 198228 KB Output is correct
48 Correct 536 ms 198224 KB Output is correct
49 Correct 618 ms 198124 KB Output is correct
50 Correct 632 ms 198212 KB Output is correct
51 Correct 503 ms 198200 KB Output is correct
52 Correct 567 ms 197980 KB Output is correct
53 Correct 519 ms 197980 KB Output is correct
54 Correct 505 ms 198208 KB Output is correct
55 Correct 645 ms 198224 KB Output is correct
56 Correct 625 ms 198092 KB Output is correct
57 Correct 626 ms 197980 KB Output is correct
58 Correct 520 ms 198200 KB Output is correct
59 Correct 514 ms 198204 KB Output is correct
60 Correct 537 ms 198204 KB Output is correct
61 Correct 536 ms 198196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 11768 KB Output is correct
2 Correct 42 ms 11516 KB Output is correct
3 Correct 53 ms 11572 KB Output is correct
4 Correct 87 ms 11740 KB Output is correct
5 Correct 70 ms 11672 KB Output is correct
6 Correct 85 ms 11716 KB Output is correct
7 Correct 61 ms 11836 KB Output is correct
8 Correct 44 ms 12024 KB Output is correct
9 Correct 48 ms 11800 KB Output is correct
10 Correct 48 ms 11724 KB Output is correct
11 Correct 72 ms 11684 KB Output is correct
12 Correct 81 ms 11720 KB Output is correct
13 Correct 70 ms 11796 KB Output is correct
14 Correct 81 ms 11720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 11908 KB Output is correct
2 Correct 60 ms 11720 KB Output is correct
3 Correct 80 ms 11716 KB Output is correct
4 Correct 106 ms 11676 KB Output is correct
5 Correct 96 ms 11716 KB Output is correct
6 Correct 100 ms 11720 KB Output is correct
7 Correct 57 ms 11724 KB Output is correct
8 Correct 48 ms 11724 KB Output is correct
9 Correct 62 ms 11716 KB Output is correct
10 Correct 89 ms 11716 KB Output is correct
11 Correct 95 ms 11580 KB Output is correct
12 Correct 75 ms 11776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 197968 KB Output is correct
2 Correct 25 ms 197968 KB Output is correct
3 Correct 27 ms 197976 KB Output is correct
4 Correct 25 ms 197936 KB Output is correct
5 Correct 26 ms 197968 KB Output is correct
6 Correct 24 ms 197972 KB Output is correct
7 Correct 25 ms 197964 KB Output is correct
8 Correct 25 ms 197972 KB Output is correct
9 Correct 24 ms 197980 KB Output is correct
10 Correct 25 ms 197880 KB Output is correct
11 Correct 25 ms 198024 KB Output is correct
12 Correct 24 ms 197940 KB Output is correct
13 Correct 24 ms 197980 KB Output is correct
14 Correct 26 ms 198048 KB Output is correct
15 Correct 25 ms 197980 KB Output is correct
16 Correct 25 ms 197968 KB Output is correct
17 Correct 24 ms 197972 KB Output is correct
18 Correct 24 ms 197988 KB Output is correct
19 Correct 24 ms 197936 KB Output is correct
20 Correct 24 ms 197972 KB Output is correct
21 Correct 24 ms 197968 KB Output is correct
22 Correct 24 ms 197972 KB Output is correct
23 Correct 24 ms 197972 KB Output is correct
24 Correct 25 ms 197968 KB Output is correct
25 Correct 25 ms 197980 KB Output is correct
26 Correct 24 ms 197968 KB Output is correct
27 Correct 26 ms 197972 KB Output is correct
28 Correct 26 ms 197976 KB Output is correct
29 Correct 25 ms 197936 KB Output is correct
30 Correct 26 ms 197972 KB Output is correct
31 Correct 24 ms 197972 KB Output is correct
32 Correct 26 ms 197976 KB Output is correct
33 Correct 27 ms 197908 KB Output is correct
34 Correct 26 ms 197976 KB Output is correct
35 Correct 31 ms 197980 KB Output is correct
36 Correct 27 ms 197980 KB Output is correct
37 Correct 26 ms 197876 KB Output is correct
38 Correct 26 ms 197972 KB Output is correct
39 Correct 27 ms 197908 KB Output is correct
40 Correct 26 ms 197940 KB Output is correct
41 Correct 132 ms 198204 KB Output is correct
42 Correct 610 ms 198336 KB Output is correct
43 Correct 29 ms 197980 KB Output is correct
44 Correct 230 ms 198184 KB Output is correct
45 Correct 245 ms 198192 KB Output is correct
46 Correct 646 ms 198220 KB Output is correct
47 Correct 513 ms 198228 KB Output is correct
48 Correct 536 ms 198224 KB Output is correct
49 Correct 618 ms 198124 KB Output is correct
50 Correct 632 ms 198212 KB Output is correct
51 Correct 503 ms 198200 KB Output is correct
52 Correct 567 ms 197980 KB Output is correct
53 Correct 519 ms 197980 KB Output is correct
54 Correct 505 ms 198208 KB Output is correct
55 Correct 645 ms 198224 KB Output is correct
56 Correct 625 ms 198092 KB Output is correct
57 Correct 626 ms 197980 KB Output is correct
58 Correct 520 ms 198200 KB Output is correct
59 Correct 514 ms 198204 KB Output is correct
60 Correct 537 ms 198204 KB Output is correct
61 Correct 536 ms 198196 KB Output is correct
62 Correct 35 ms 11768 KB Output is correct
63 Correct 42 ms 11516 KB Output is correct
64 Correct 53 ms 11572 KB Output is correct
65 Correct 87 ms 11740 KB Output is correct
66 Correct 70 ms 11672 KB Output is correct
67 Correct 85 ms 11716 KB Output is correct
68 Correct 61 ms 11836 KB Output is correct
69 Correct 44 ms 12024 KB Output is correct
70 Correct 48 ms 11800 KB Output is correct
71 Correct 48 ms 11724 KB Output is correct
72 Correct 72 ms 11684 KB Output is correct
73 Correct 81 ms 11720 KB Output is correct
74 Correct 70 ms 11796 KB Output is correct
75 Correct 81 ms 11720 KB Output is correct
76 Correct 38 ms 11908 KB Output is correct
77 Correct 60 ms 11720 KB Output is correct
78 Correct 80 ms 11716 KB Output is correct
79 Correct 106 ms 11676 KB Output is correct
80 Correct 96 ms 11716 KB Output is correct
81 Correct 100 ms 11720 KB Output is correct
82 Correct 57 ms 11724 KB Output is correct
83 Correct 48 ms 11724 KB Output is correct
84 Correct 62 ms 11716 KB Output is correct
85 Correct 89 ms 11716 KB Output is correct
86 Correct 95 ms 11580 KB Output is correct
87 Correct 75 ms 11776 KB Output is correct
88 Incorrect 75 ms 11728 KB Output isn't correct
89 Halted 0 ms 0 KB -