# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
227788 | dolphingarlic | Matching (CEOI11_mat) | C++14 | 2059 ms | 65540 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int p[1000001], h[1000001], l_pred[1000001], l_succ[1000001], partial[1000001];
vector<int> matches;
inline bool can_extend(int i, int j, int *v) {
return ((!l_pred[j + 1] || v[i - l_pred[j + 1]] < v[i]) && (!l_succ[j + 1] || v[i] < v[i - l_succ[j + 1]]));
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
p[x - 1] = i;
}
for (int i = 0; i < m; i++) scanf("%d", h + i);
set<pair<int, int>> l;
for (int i = 0; i < n; i++) l.insert({p[i], i});
for (int i = n - 1; ~i; i--) {
auto x = l.find({p[i], i});
l_pred[i] = i - (x == l.begin() ? i : (*prev(x)).second);
l_succ[i] = i - (x == prev(l.end()) ? i : (*next(x)).second);
l.erase(x);
}
for (int i = 1, j = partial[0] = -1; i < n; i++) {
while (~j && !can_extend(i, j, p)) j = partial[j];
if (can_extend(i, j, p)) j++;
partial[i] = j;
}
for (int i = 0, j = -1; i < m; i++) {
while (~j && !can_extend(i, j, h)) j = partial[j];
if (can_extend(i, j, h)) j++;
if (j == n - 1) {
matches.push_back(i - n + 2);
j = partial[j];
}
}
printf("%d\n", matches.size());
for (int i : matches) printf("%d ", i);
printf("\n");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |