Submission #516736

# Submission time Handle Problem Language Result Execution time Memory
516736 2022-01-22T04:42:06 Z nickyrio Exam (eJOI20_exam) C++17
77 / 100
239 ms 524292 KB
#include <bits/stdc++.h>

using namespace std;
#define all(s) s.begin(), s.end() 
const int N = 1e5 + 100;

int a[N], b[N], n, L[N], R[N];
vector<int> e[N];
vector<int> dp[N];


void sub2() {
    for (int i = 2; i <= n; ++i) if (b[i] != b[1]) return;
    int cnt = 0;
    // cerr << "Sub 2" << '\n';
    for (int i = 1; i <= n; ++i) if (a[i] == b[1]) {
        for (int j = i - 1; a[j] < a[i]; --j) a[j] = a[i];
        for (int j = i + 1; a[j] < a[i]; ++j) a[j] = a[i];
        // cerr << i << ' ' << L[i] << ' ' << R[i] << '\n';
        // for (int j = L[i] + 1; j < R[i]; ++j) a[j] = b[1];
    }
    for (int i = 1; i <= n; ++i) if (a[i] == b[1]) ++cnt;
    cout << cnt << '\n';
    exit(0);
}

void sub5() {

}
int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> b[i];
    a[0] = a[n + 1] = 2e9;
    sub2();
    sub5();
    for (int i = 1; i <= n; ++i) {
        L[i] = R[i] = i;
        while (a[L[i]] <= a[i]) --L[i];
        while (a[R[i]] <= a[i]) ++R[i];
    }
    for (int i = 0; i <= n; ++i) dp[i].assign(n + 1, 0);
    vector<int> Ranking(a + 1, a + n + 1);
    sort(all(Ranking));
    Ranking.resize(unique(all(Ranking)) - Ranking.begin());
    for (int i = 1; i <= n; ++i) {
        a[i] = lower_bound(all(Ranking), a[i]) - Ranking.begin();
        int temp_b = lower_bound(all(Ranking), b[i]) - Ranking.begin();
        if (temp_b != Ranking.size() && Ranking[temp_b] != b[i]) temp_b = Ranking.size();
        b[i] = temp_b;
        e[b[i]].push_back(i);
    }

    for (int i = 1; i <= n; ++i) {
        int temp = 1;
        int p = 0, cnt = 0;
        for (int j : e[a[i]]) if (L[i] < j && j < R[i]) {
            ++cnt;
            if (dp[i - 1][j - 1] + 1 > dp[i - 1][p] + cnt) { p = j - 1; cnt = 1; }
            dp[i][j] = max(dp[i][j], dp[i - 1][p] + cnt);
        }
        for (int j = 1; j <= n; ++j) dp[i][j] = max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]));
    }
    cout << dp[n][n] << '\n';
}

Compilation message

exam.cpp: In function 'int main()':
exam.cpp:50:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if (temp_b != Ranking.size() && Ranking[temp_b] != b[i]) temp_b = Ranking.size();
      |             ~~~~~~~^~~~~~~~~~~~~~~~~
exam.cpp:56:13: warning: unused variable 'temp' [-Wunused-variable]
   56 |         int temp = 1;
      |             ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 7 ms 5068 KB Output is correct
3 Correct 15 ms 5724 KB Output is correct
4 Correct 14 ms 6100 KB Output is correct
5 Correct 25 ms 7804 KB Output is correct
6 Correct 13 ms 6144 KB Output is correct
7 Correct 14 ms 6232 KB Output is correct
8 Correct 25 ms 7620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 5964 KB Output is correct
3 Correct 29 ms 20796 KB Output is correct
4 Correct 150 ms 95436 KB Output is correct
5 Correct 157 ms 103108 KB Output is correct
6 Correct 160 ms 103080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 103176 KB Output is correct
2 Runtime error 239 ms 524292 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 2 ms 5068 KB Output is correct
10 Correct 3 ms 5196 KB Output is correct
11 Correct 3 ms 5196 KB Output is correct
12 Correct 3 ms 5196 KB Output is correct
13 Correct 3 ms 5196 KB Output is correct
14 Correct 4 ms 5196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 5964 KB Output is correct
9 Correct 29 ms 20796 KB Output is correct
10 Correct 150 ms 95436 KB Output is correct
11 Correct 157 ms 103108 KB Output is correct
12 Correct 160 ms 103080 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 2 ms 5068 KB Output is correct
16 Correct 3 ms 5196 KB Output is correct
17 Correct 3 ms 5196 KB Output is correct
18 Correct 3 ms 5196 KB Output is correct
19 Correct 3 ms 5196 KB Output is correct
20 Correct 4 ms 5196 KB Output is correct
21 Correct 4 ms 5116 KB Output is correct
22 Correct 9 ms 8908 KB Output is correct
23 Correct 5 ms 4940 KB Output is correct
24 Correct 180 ms 103020 KB Output is correct
25 Correct 159 ms 103104 KB Output is correct
26 Correct 156 ms 103092 KB Output is correct
27 Correct 154 ms 103096 KB Output is correct
28 Correct 172 ms 103132 KB Output is correct
29 Correct 159 ms 103116 KB Output is correct
30 Correct 159 ms 103120 KB Output is correct
31 Correct 158 ms 103108 KB Output is correct
32 Correct 157 ms 103116 KB Output is correct