# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
383005 | 2021-03-28T17:25:22 Z | valerikk | Exam (eJOI20_exam) | C++17 | 240 ms | 122860 KB |
#include <bits/stdc++.h> using namespace std; const int N = 5005; const int M = 1e5 + 7; int n; int a[M], b[M]; bool ok[N][N]; int dp[N][N]; void solve_b_equal() { int B = b[0]; vector<int> inds; inds.push_back(-1); for (int i = 0; i < n; ++i) { if (a[i] > B) inds.push_back(i); } inds.push_back(n); int ans = 0; for (int i = 0; i + 1 < inds.size(); ++i) { bool ok = false; for (int j = inds[i] + 1; j < inds[i + 1]; ++j) { ok |= a[j] == B; } if (ok) ans += inds[i + 1] - inds[i] - 1; } cout << ans << endl; } void solve_a_distinct() { } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; bool b_equal = true; for (int i = 1; i < n; ++i) b_equal &= b[i] == b[i - 1]; if (b_equal) { solve_b_equal(); return 0; } /*vector<int> A; for (int i = 0; i < n; ++i) A.push_back(a[i]); sort(A.begin(), A.end()); bool a_distinct = true; for (int i = 1; i < n; ++i) a_distinct &= A[i] != A[i - 1]; if (a_distinct) { solve_a_distinct(); }*/ for (int i = 0; i < n; ++i) { ok[i][i] = true; for (int j = i - 1; j >= 0; --j) { if (a[j] > a[i]) break; ok[j][i] = true; } for (int j = i + 1; j < n; ++j) { if (a[j] > a[i]) break; ok[j][i] = true; } } for (int i = 0; i < n; ++i) { if (ok[0][i] && b[0] == a[i]) { dp[0][i] = 1; } } for (int i = 1; i < n; ++i) { int mx = 0; for (int j = 0; j < n; ++j) { mx = max(mx, dp[i - 1][j]); if (ok[i][j]) { dp[i][j] = mx; if (b[i] == a[j]) ++dp[i][j]; } } } int ans = 0; for (int i = 0; i < n; ++i) ans = max(ans, dp[n - 1][i]); cout << ans << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 2 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 6 ms | 620 KB | Output is correct |
3 | Correct | 18 ms | 2540 KB | Output is correct |
4 | Correct | 14 ms | 1516 KB | Output is correct |
5 | Correct | 28 ms | 3180 KB | Output is correct |
6 | Correct | 19 ms | 2160 KB | Output is correct |
7 | Correct | 16 ms | 1644 KB | Output is correct |
8 | Correct | 31 ms | 3440 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 4 ms | 5100 KB | Output is correct |
3 | Correct | 31 ms | 25580 KB | Output is correct |
4 | Correct | 198 ms | 86840 KB | Output is correct |
5 | Correct | 204 ms | 91500 KB | Output is correct |
6 | Correct | 231 ms | 91628 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 79 ms | 84096 KB | Output is correct |
2 | Runtime error | 64 ms | 43500 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 2 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 492 KB | Output is correct |
8 | Correct | 1 ms | 620 KB | Output is correct |
9 | Correct | 2 ms | 1260 KB | Output is correct |
10 | Correct | 2 ms | 2156 KB | Output is correct |
11 | Correct | 2 ms | 2028 KB | Output is correct |
12 | Correct | 2 ms | 2156 KB | Output is correct |
13 | Correct | 2 ms | 2028 KB | Output is correct |
14 | Correct | 2 ms | 2028 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 2 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 492 KB | Output is correct |
8 | Correct | 4 ms | 5100 KB | Output is correct |
9 | Correct | 31 ms | 25580 KB | Output is correct |
10 | Correct | 198 ms | 86840 KB | Output is correct |
11 | Correct | 204 ms | 91500 KB | Output is correct |
12 | Correct | 231 ms | 91628 KB | Output is correct |
13 | Correct | 1 ms | 492 KB | Output is correct |
14 | Correct | 1 ms | 620 KB | Output is correct |
15 | Correct | 2 ms | 1260 KB | Output is correct |
16 | Correct | 2 ms | 2156 KB | Output is correct |
17 | Correct | 2 ms | 2028 KB | Output is correct |
18 | Correct | 2 ms | 2156 KB | Output is correct |
19 | Correct | 2 ms | 2028 KB | Output is correct |
20 | Correct | 2 ms | 2028 KB | Output is correct |
21 | Correct | 2 ms | 2156 KB | Output is correct |
22 | Correct | 9 ms | 12268 KB | Output is correct |
23 | Correct | 2 ms | 364 KB | Output is correct |
24 | Correct | 240 ms | 122856 KB | Output is correct |
25 | Correct | 113 ms | 122860 KB | Output is correct |
26 | Correct | 89 ms | 122860 KB | Output is correct |
27 | Correct | 86 ms | 115308 KB | Output is correct |
28 | Correct | 75 ms | 80748 KB | Output is correct |
29 | Correct | 199 ms | 91500 KB | Output is correct |
30 | Correct | 204 ms | 91440 KB | Output is correct |
31 | Correct | 200 ms | 91628 KB | Output is correct |
32 | Correct | 118 ms | 68844 KB | Output is correct |