-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlab13part2
94 lines (94 loc) · 2.18 KB
/
lab13part2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O2")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#define p_q priority_queue
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
void DEBUG_ARR(vt<T> a)
{
f(i,0,a.size())cout<<a[i]<<" ";
cout<<"\n";
}
int popcount(lli x){
int ans=0;
while(x>0){
if((x&1)==1)ans++;
x=x>>1;
}
return ans;
}
const lli tp=1e7+19;
bool hash_table[5][tp];
lli primes[5];
lli prime_powers[114][101];
lli calc_hash(string s,lli p){
lli hash=0;
f(i,0,s.size()){
if(s[i]<='Z')
hash=((hash+(s[i]-'A'+26)*(prime_powers[p][i])))%tp;
else hash=((hash+(s[i]-'a')*(prime_powers[p][i])))%tp;
}
if(hash<0)hash+=tp;
return hash;
}
int main()
{
fastio;
int n;cin>>n;
vt <string> s(n);
f(i,0,n)cin>>s[i];
primes[0]=3;
primes[1]=11;
primes[2]=31;
primes[3]=101;
primes[4]=113;
prime_powers[3][0]=prime_powers[11][0]=prime_powers[31][0]=prime_powers[101][0]=prime_powers[113][0]=1;
f(i,1,101){
f(j,0,5){
prime_powers[primes[j]][i]=(primes[j]*prime_powers[primes[j]][i-1])%tp;
}
}
f(i,0,n){
f(j,0,5){
hash_table[j][calc_hash(s[i],primes[j])]=1;
}
}
f(i,0,n){
string temp=s[i];
reverse(s[i].begin(),s[i].end());
if(temp==s[i])continue;
int cnt=0;
f(j,0,5){
cnt+=hash_table[j][calc_hash(s[i],primes[j])];
}
if(cnt==5){
cout<<"YES\n";
return 0;
}
}
cout<<"NO\n";
return 0;
}