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 <cstdio>
#include <algorithm>
#include <set>
using namespace std;
set<long long> hash_virus[101];
long long chash[1005];
int n,k;
int fnd(long long x){
for (int i=1; i<n; i++) {
if(hash_virus[i].find(x) == hash_virus[i].end()) return 0;
}
return 1;
}
int main(){
int n,k;
scanf("%d %d",&n,&k);
chash[0] = 1;
for (int i=1; i<=k; i++) {
chash[i] = chash[i-1] * 10007;
}
for (int i=0; i<n; i++) {
int m, a[1005] ={};
scanf("%d",&m);
for (int j=0; j<m; j++) {
scanf("%d",&a[j]);
}
long long ch = 0;
for (int j=0; j<m; j++) {
ch *= 10007;
ch += a[j];
if(j+1 >= k){
hash_virus[i].insert(ch);
ch -= a[j-k+1] * chash[k];
}
}
reverse(a,a+m);
ch = 0;
for (int j=0; j<m; j++) {
ch *= 10007;
ch += a[j];
if(j+1 >= k){
hash_virus[i].insert(ch);
ch -= a[j-k+1] * chash[k];
}
}
}
set<long long> ::iterator it = hash_virus[0].begin();
while (it != hash_virus[0].end()) {
if(fnd(*it)){
puts("YES");
return 0;
}
it++;
}
puts("NO");
}
# | 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... |