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 = 10005;
int scor[N][N];
int ans[N][N];
int v[N];
int l;
int getscor(int x, int y){
int ans = 0;
for(int i = 0; i < l; i++){
if(v[x + i] != v[y + i])
ans++;
}
return ans;
}
int main()
{
//freopen(".in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n;
cin>>n>>l;
for(int i = 1; i<=n; i++)
cin>>v[i];
for(int i = 2; i <= n - l + 1; i++){
scor[1][i] = getscor(1, i);
}
for(int i = 2; i <= n - l + 1; i++){
for(int j = i + 1; j <= n - l + 1; j++){
scor[i][j] = scor[i - 1][j - 1] - (v[i - 1] != v[j - 1]) + (v[i + l -1] != v[j + l - 1]);
}
}
for(int i = 1; i <= n -l + 1; i++){
for(int j = i + 1; j <= n- l + 1; j++){
ans[i][scor[i][j]]++;
ans[j][scor[i][j]]++;
}
}
for(int i =1 ; i<=n -l + 1; i++){
for(int j = 0; j<= l; j++)
if(j)
ans[i][j] += ans[i][j - 1];
}
int q;
cin>>q;
for(int i =1 ; i<=q; i++){
int k;
cin>>k;
for(int j = 1; j <= n -l + 1; j++)
cout<<ans[j][k]<<" ";
cout<<"\n";
}
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... |