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>
#define ll long long int
using namespace std;
#define ll long long int
int NM = 600, p = 31, n, k;
ll m = (ll)1<<55;
string s;
vector< vector< pair<ll, ll>> > v(NM);
vector<int> ppow(NM, 1);
int get(char c){
return c-'a';
}
void hashF(int red){
for(int i=0; i+k <= n; i++){
vector<int> kv;
vector<int> ost;
for(int j=0; j<k; j++)
kv.push_back(get(s[i+j]));
sort(kv.begin(), kv.end());
ll ret = 0, ret2 = 0;
for(int j=0; j<k; j++){
ret += kv[j]*ppow[j];
ret = ret % m;
}
for(int j=0; j<i; j++)
ost.push_back(get(s[j]));
for(int j=i+k; j<n; j++)
ost.push_back(get(s[j]));
for(int j=0; j<n-k; j++){
ret2 += ost[j]*ppow[j];
ret2 = ret2 % m;
}
v[red].push_back(make_pair(ret, ret2));
}
}
int main(){
cin.tie(NULL);
ios::sync_with_stdio(false);
cin >> n >> k;
for(int i=1; i<k+2; i++) ppow[i] = (p*ppow[i-1])%m;
for(int i=0; i<n; i++){
cin>>s;
hashF(i);
}
int d = v[0].size();
for(int i=0; i<d; i++){//biramo kolone
for(int a=0; a<n; a++)
for(int b=a+1; b<n; b++)
if(v[a][i]==v[b][i]){
cout<<"DA";
return 0;
}
}
cout<<"NE";
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... |
# | 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... |