이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |