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;
const int N = 1e4 + 5;
int n , l , a[N] , c[N];
int Q[N];
vector<int> B[N];
int main (){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> l;
for(int i = 1; i <= n; ++i) cin >> a[i];
int q;
cin >> q;
for(int i = 0; i < q; ++i) cin >> Q[i];
if(q == 1 && Q[0] == 0){
memset(c , -1 , sizeof(c));
for(int i = 1; i <= n - l + 1; ++i){
int p = i;
for(int j = 0; j <= n; ++j){
if(i + p > l) c[i]++ , p = i;
if(a[p] == a[j])p++;
else p = i;
}
}
for(int i = 1;i <= n - l + 1; ++i)cout << c[i] << " ";
return 0;
}
for(int i = 1; i <= n - l+1; ++i){
for(int j = i + 1; j <= n - l+1; ++j){
int cnt = 0;
for(int k = 0; k < l; ++k){
if(a[i + k] != a[j + k]) cnt++;
}
B[i].emplace_back(cnt);
B[j].emplace_back(cnt);
}
}
for(int i = 1; i <= n - l+1; ++i) sort(B[i].begin() , B[i].end());
/*
for(int i = 1; i <= n -l+1; ++i){
for(int x : B[i])cout << x << " ";cout << endl;
}
*/
for(int i = 0; i < q; ++i){
for(int j = 1; j <= n-l+1; ++j) cout << upper_bound(B[j].begin() , B[j].end() , Q[i]) - B[j].begin() << ' ';
cout << endl;
}
return 0;
}
# | 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... |