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(){
scanf("%d %d",&n,&k);
chash[0] = 1;
for (int i=1; i<=k; i++) {
chash[i] = chash[i-1] * 10000;
}
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 *= 10000;
ch += a[j];
if(j >= k) ch -= a[j-k] * chash[k];
if(j+1 >= k) hash_virus[i].insert(ch);
}
reverse(a,a+m);
ch = 0;
for (int j=0; j<m; j++) {
ch *= 10000;
ch += a[j];
if(j >= k) ch -= a[j-k] * chash[k];
if(j+1 >= k) hash_virus[i].insert(ch);
}
}
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... |