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

#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
*/
UVALive 6507 Passwords的更多相关文章
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- Cracking Story - How I Cracked Over 122 Million SHA1 and MD5 Hashed Passwords
This is the story about how I cracked 122 million* password hashes with John the Ripper and oclHashc ...
- codeforces 721B B. Passwords(贪心)
题目链接: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
随机推荐
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- jmeter(三)参数传递
[一]参数化 录制脚本中有登录操作,需要输入用户名和密码,假如系统不允许相同的用户名和密码同时登录,或者想更好的模拟多个用户来登录系统. 这个时候就需要对用户名和密码进行参数化,使每个虚拟用户都使用不 ...
- 转】在Ubuntu中安装Redis
不多说,直接上干货! 原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/ 感谢! 在Ubuntu中安装Redis R利剑 ...
- composer Failed to decode zlib stream 无法解码zlib流
Win7 中安装 Composer (PHP) 国内有些网络不能访问美国的Composer官网,可访问 Composer 中文网 学习. 目标 可以在任何目录下的项目中执行 PHP composer. ...
- 策略模式--Java篇
策略模式(Strategy):它定义了算法家族,分别封装起来,让他们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户. 下面将以商场打折为例子,说明策略模式.商场收银如何促销,用打折还是 ...
- 机器学习-牛顿方法&指数分布族&GLM
本节内容 牛顿方法 指数分布族 广义线性模型 之前学习了梯度下降方法,关于梯度下降(gradient descent),这里简单的回顾下[参考感知机学习部分提到的梯度下降(gradient desce ...
- iOS地图----MapKit框架
1.MapKit框架使用前提 ①导入框架 ②导入主头文件 #import <MapKit/MapKit.h> ③MapKit框架使用须知 MapKit框架中所有数据类型的前缀都是MK Ma ...
- js 日期时间大小比较
<body> 开始时间:<input onfocus="setday(this)" id="startTime" name="sta ...
- angular2快速开始
简介 5 分钟从0搭建一个ng2项目demohttps://angular.io/docs/js/latest/quickstart.html 你运气真好,竟然看到了这篇文章,你省事了,一分钟让你完成 ...
- 洛谷——P2680 运输计划
https://www.luogu.org/problem/show?pid=2680 题目背景 公元 2044 年,人类进入了宇宙纪元. 题目描述 L 国有 n 个星球,还有 n-1 条双向航道,每 ...