# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1240525 | bncodero_o123 | Matching (CEOI11_mat) | C++20 | 69 ms | 12612 KiB |
#include <bits/stdc++.h>
#define ll long long
#define name "code"
using namespace std;
const int max_n= 1e6;
int n, m, p[max_n + 2], h[max_n + 2];
int pos[max_n + 2], a[max_n + 2], b[max_n + 2];
int kmp[max_n + 2];
void solve() {
cin >> n >> m;
for(int i= 1; i <= n; ++i) cin >> p[i], pos[p[i]]= i;
for(int i= 1; i <= m; ++i) cin >> h[i];
for(int i= 1; i < n; ++i) a[i]= pos[i + 1] > pos[i];
for(int i= 1; i < m; ++i) b[i]= h[i + 1] > h[i];
a[n]= 2;
for(int i= 2, j= 0; i < n; ++i) {
while(j && a[i] != a[j + 1]) j= kmp[j];
kmp[i]= j += a[i] == a[j + 1];
}
int ans= 0;
for(int i= 1, j= 0; i < m; ++i) {
while(j && b[i] != a[j + 1]) j= kmp[j];
j += b[i] == a[j + 1];
ans += j == n - 1;
}
cout << ans << '\n';
}
signed main() {
ios_base:: sync_with_stdio(false);
cin.tie(NULL);
if(fopen(name".inp", "r")) {
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
int T= 1;
for(; T; --T) solve();
return 0;
}
컴파일 시 표준 에러 (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... |