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 #212 (Div. 2) A. Two Semiknights Meet
题目传送门 /* 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 */ #include <cstdio> #include <al ...
- C#代码规范(简版)
C#项目代码规范 目的 1.方便代码的交流和维护. 2.不影响编码的效率,不与大众习惯冲突. 3.使代码更美观.阅读更方便. 4.使代码的逻辑更清晰.更易于理解. 在C#中通常使用的两种编码方式如下 ...
- R in action读书笔记(15)第十一章 中级绘图 之二 折线图 相关图 马赛克图
第十一章 中级绘图 本节用到的函数有: plot legend corrgram mosaic 11.2折线图 如果将散点图上的点从左往右连接起来,那么就会得到一个折线图. 创建散点图和折线图: &g ...
- [翻译] API测试最佳实践 - 身份验证(Authentication)
API测试最佳实践 - 身份验证 适用等级:高级 1. 概况 身份验证通常被定义为是对某个资源的身份的确认的活动,这里面资源的身份指代的是API的消费者(或者说是调用者).一旦一个用户的身份验证通过了 ...
- DLL线程中坑爹的Synchronize?
1, 缘起 某次开发语音对讲windows程序,采用delphi语言,及delphix的TDXSound控件. DXSound提供了TSoundCaptureStream类,可以实现指定频率.位数.声 ...
- Linux下Eclipse连接小米手机真机调试
以前用Ubuntu 12.04可以真机调试,连上手机就可以了,上次看pear os 好看于是下了个玩玩(界面风格像mac 买不起,仿得起),这次想开发安卓发现真机调试不了了...于是乎各种找资料,各种 ...
- 解决max解析记录与cname不能共存的问题
问题描述: 在腾讯上做了域名邮箱解析,需要将max记录绑定到主机记录为@(即空)的记录下. 而在做域名解析的时候,为了方便,需要将不带3w的域名也要解析到主机记录为@(即空)的记录下. 因此,解析报错 ...
- php的一个魔法常亮__DIR__
我们知道PHP中提供了一个魔术常量(magic constant)__FILE__,用来指向当前执行的PHP脚本.但PHP没有直接提供该脚本所在目录的常量.也就是说如果我们要得到当前PHP脚本所在的目 ...
- H3C AR28-31路由器组网实验
接线图 可以发现PC1和PC2不在一个网段上,如果不靠路由器就不可能ping,所以要用路由器组网 接线步骤 串行线连接路由器1与路由器2 以太网线连路由器以太网口 与 交换机接口 计算机网线连交换机口 ...
- discuz 插件核心函数hookscript分析.
function hookscript($script, $hscript, $type = 'funcs', $param = array(), $func = '', $scriptextra = ...