Passwords

Time Limit: 3000ms
Memory Limit: 131072KB

This problem will be judged on UVALive. Original ID: 6507
64-bit integer IO format: %lld      Java class name: Main

 
解题:好高深的hash啊
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
const int base = ;
const int mod = 1e9+;
char str[maxn][];
LL hs[maxn][],B[];
int n;
unordered_map<LL,int>ump;
void init(){
B[] = ;
for(int i = ; i < ; ++i)
B[i] = B[i-]*base%mod;
}
LL calc(int i,int L,int R){
return ((hs[i][R] - hs[i][L-]*B[R - L + ])%mod + mod)%mod;
}
void solve(){
ump.clear();
for(int i = ; i < n; ++i){
for(int j = ,len = strlen(str[i] + ); j <= len; ++j){
hs[i][j] = (hs[i][j-]*base + str[i][j])%mod;
ump[hs[i][j]]++;
}
}
int a = ,b = ;
for(int i = ; i < n; ++i){
int len = strlen(str[i] + );
for(int j = ; j <= len; ++j) --ump[hs[i][j]];
for(int j = ; j <= len; ++j){
LL suffix = calc(i,len - j + ,len);
if(!ump[suffix]) continue;
int x = ,y = ;
LL prefix = suffix;
for(int k = ; k*j <= len; ++k){
LL suffix2 = calc(i,len - j*k + ,len);
prefix = (prefix*B[j] + suffix)%mod;
if(suffix2 != prefix) break;
if(ump[prefix]) x = k;
y = k;
}
if(x == y && x == ) continue;
if(x == y) --x;
if(j*(x + y) > a + b){
a = x*j;
b = y*j;
}
}
for(int j = ; j <= len; ++j) ump[hs[i][j]]++;
}
printf("%d %d\n",a,b);
}
int main(){
int kase;
init();
scanf("%d",&kase);
while(kase--){
scanf("%d",&n);
for(int i = ; i < n; ++i)
scanf("%s",str[i] + );
solve();
}
return ;
}
/*
2
3
abcabe
defg
bcabab
*/

最新文章

  1. python爬乌云dorps文章
  2. POJ 2549 二分+HASH
  3. IIS+PHP配置一次成功无错误版
  4. DTD 知识归纳总结
  5. jQuery 显示加载更多
  6. Uploadify 上传失败
  7. 【网贷投资手册】P2P行业揭秘
  8. Python基础第三天
  9. DryIoc mvc 项目集成
  10. MySQL 同步状态
  11. C#100万条数据导入SQL SERVER数据库仅用4秒 (附源码)
  12. poj 3764 The xor-longest Path (01 Trie)
  13. js获取url指定参数值
  14. KFCM算法的matlab程序(用FCM初始化聚类中心)
  15. 解决y7000笔记本ubuntu18.04下 休眠挂起后唤醒花屏
  16. bzoj4326 树链剖分 + 线段树 // 二分 lca + 树上差分
  17. Linux下安装Gensim
  18. 计算概论(A)/基础编程练习2(8题)/5:点和正方形的关系
  19. readline与readlines之间的简单区别
  20. [A] 1046 Shortest Distance

热门文章

  1. ACM_回文素数
  2. .NET下集中实现AOP编程的框架
  3. 自定义View(12)绘制.9图片
  4. 204 Count Primes 计数质数
  5. [转]mysql日志详细解析
  6. Sql Server把本地数据库传到服务器数据库
  7. .net 环境下c# 通信
  8. Linux之测试服务器和端口连通
  9. 12 DOM操作应用
  10. ES5之变量