# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
599064 |
2022-07-19T09:49:31 Z |
isaachew |
Lottery (CEOI18_lot) |
C++17 |
|
993 ms |
12740 KB |
#include <bits/stdc++.h>
/*
Hamming distance
High time limit - O(n^2)? O(n sqrt n Q)?
ST1: O(nlq)?
ST3: find exact matches in O(N log N)
Find number of strings with Hamming distance <= k
O(n^2l)
Precompute everything
Speed up finding differences
Differences can be found in O(n^2) by marking which numbers are the same as the number x away
Differences between x and x+n found
k<=l
*/
int n,l;
int main(){
std::cin>>n>>l;
std::vector<int> a;
for(int i=0;i<n;i++){
int x;
std::cin>>x;
a.push_back(x);
}
std::vector<int> queries;
std::vector<int> s_indices;
std::vector<int> qlt;
int q;
std::cin>>q;
for(int j=q;j--;){
int k;
std::cin>>k;
queries.push_back(k);
s_indices.push_back(j);
}
s_indices.push_back(q);
queries.push_back(l+1);
std::sort(s_indices.begin(),s_indices.end(),[queries](int a,int b){return queries[a]<queries[b];});
int nqs=0;
for(int i=0;i<=l;i++){
while(i>queries[s_indices[nqs]]){
nqs++;
}
qlt.push_back(nqs);
//std::cout<<nqs<<'\n';
}
std::vector<std::vector<int>> diffcnt(n-l+1,std::vector<int>(q+1));
for(int d=1;d<=n-l;d++){
std::vector<bool> diff_ds;
for(int i=0;i<n-d;i++){
diff_ds.push_back(a[i]!=a[i+d]);
}
int sumd=0;
for(int i=-l+1;i<n-l+1;i++){
if(i<=n-l){
sumd+=diff_ds[i+l-1];
}
if(i>0){
sumd-=diff_ds[i-1];
}
if(i>=0&&i<(n-l+1)-d){
//std::cout<<i<<' '<<i+d<<' '<<sumd<<'\n';
diffcnt[i][qlt[sumd]]++;
diffcnt[i+d][qlt[sumd]]++;
}
}
}
std::vector<std::vector<int>> tdiffs(n-l+1,std::vector<int>(q+1));
for(int i=0;i<n-l+1;i++){
int cur=0;
for(int j=0;j<=q;j++){
cur+=diffcnt[i][j];
tdiffs[i][j]=cur;
}
}
for(int i=0;i<q;i++){
int ind=0;
while(s_indices[ind]!=i)ind++;//linear search; doesn't matter
for(int j=0;j<n-l+1;j++){
std::cout<<tdiffs[j][ind]<<' ';
}
std::cout<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
37 ms |
524 KB |
Output is correct |
14 |
Correct |
24 ms |
596 KB |
Output is correct |
15 |
Correct |
22 ms |
552 KB |
Output is correct |
16 |
Correct |
35 ms |
760 KB |
Output is correct |
17 |
Correct |
35 ms |
624 KB |
Output is correct |
18 |
Correct |
32 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
880 ms |
1392 KB |
Output is correct |
2 |
Correct |
896 ms |
1400 KB |
Output is correct |
3 |
Correct |
808 ms |
1396 KB |
Output is correct |
4 |
Correct |
860 ms |
1484 KB |
Output is correct |
5 |
Correct |
338 ms |
880 KB |
Output is correct |
6 |
Correct |
805 ms |
1372 KB |
Output is correct |
7 |
Correct |
335 ms |
876 KB |
Output is correct |
8 |
Correct |
548 ms |
1124 KB |
Output is correct |
9 |
Correct |
836 ms |
1384 KB |
Output is correct |
10 |
Correct |
858 ms |
1388 KB |
Output is correct |
11 |
Correct |
46 ms |
428 KB |
Output is correct |
12 |
Correct |
498 ms |
1108 KB |
Output is correct |
13 |
Correct |
430 ms |
936 KB |
Output is correct |
14 |
Correct |
412 ms |
940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
880 ms |
1392 KB |
Output is correct |
2 |
Correct |
896 ms |
1400 KB |
Output is correct |
3 |
Correct |
808 ms |
1396 KB |
Output is correct |
4 |
Correct |
860 ms |
1484 KB |
Output is correct |
5 |
Correct |
338 ms |
880 KB |
Output is correct |
6 |
Correct |
805 ms |
1372 KB |
Output is correct |
7 |
Correct |
335 ms |
876 KB |
Output is correct |
8 |
Correct |
548 ms |
1124 KB |
Output is correct |
9 |
Correct |
836 ms |
1384 KB |
Output is correct |
10 |
Correct |
858 ms |
1388 KB |
Output is correct |
11 |
Correct |
46 ms |
428 KB |
Output is correct |
12 |
Correct |
498 ms |
1108 KB |
Output is correct |
13 |
Correct |
430 ms |
936 KB |
Output is correct |
14 |
Correct |
412 ms |
940 KB |
Output is correct |
15 |
Correct |
846 ms |
1380 KB |
Output is correct |
16 |
Correct |
777 ms |
1344 KB |
Output is correct |
17 |
Correct |
883 ms |
1392 KB |
Output is correct |
18 |
Correct |
870 ms |
1392 KB |
Output is correct |
19 |
Correct |
875 ms |
1388 KB |
Output is correct |
20 |
Correct |
852 ms |
1400 KB |
Output is correct |
21 |
Correct |
882 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
37 ms |
524 KB |
Output is correct |
14 |
Correct |
24 ms |
596 KB |
Output is correct |
15 |
Correct |
22 ms |
552 KB |
Output is correct |
16 |
Correct |
35 ms |
760 KB |
Output is correct |
17 |
Correct |
35 ms |
624 KB |
Output is correct |
18 |
Correct |
32 ms |
716 KB |
Output is correct |
19 |
Correct |
880 ms |
1392 KB |
Output is correct |
20 |
Correct |
896 ms |
1400 KB |
Output is correct |
21 |
Correct |
808 ms |
1396 KB |
Output is correct |
22 |
Correct |
860 ms |
1484 KB |
Output is correct |
23 |
Correct |
338 ms |
880 KB |
Output is correct |
24 |
Correct |
805 ms |
1372 KB |
Output is correct |
25 |
Correct |
335 ms |
876 KB |
Output is correct |
26 |
Correct |
548 ms |
1124 KB |
Output is correct |
27 |
Correct |
836 ms |
1384 KB |
Output is correct |
28 |
Correct |
858 ms |
1388 KB |
Output is correct |
29 |
Correct |
46 ms |
428 KB |
Output is correct |
30 |
Correct |
498 ms |
1108 KB |
Output is correct |
31 |
Correct |
430 ms |
936 KB |
Output is correct |
32 |
Correct |
412 ms |
940 KB |
Output is correct |
33 |
Correct |
846 ms |
1380 KB |
Output is correct |
34 |
Correct |
777 ms |
1344 KB |
Output is correct |
35 |
Correct |
883 ms |
1392 KB |
Output is correct |
36 |
Correct |
870 ms |
1392 KB |
Output is correct |
37 |
Correct |
875 ms |
1388 KB |
Output is correct |
38 |
Correct |
852 ms |
1400 KB |
Output is correct |
39 |
Correct |
882 ms |
1400 KB |
Output is correct |
40 |
Correct |
888 ms |
3496 KB |
Output is correct |
41 |
Correct |
56 ms |
716 KB |
Output is correct |
42 |
Correct |
902 ms |
3364 KB |
Output is correct |
43 |
Correct |
874 ms |
3104 KB |
Output is correct |
44 |
Correct |
880 ms |
3148 KB |
Output is correct |
45 |
Correct |
993 ms |
12740 KB |
Output is correct |
46 |
Correct |
62 ms |
1536 KB |
Output is correct |
47 |
Correct |
973 ms |
12728 KB |
Output is correct |
48 |
Correct |
936 ms |
10704 KB |
Output is correct |
49 |
Correct |
907 ms |
11400 KB |
Output is correct |