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 #166 (Div. 2) B. Prime Matrix
题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...
- jQuery Ajax使用实例
<script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.js"></script> <scr ...
- js的replace函数把"$"替换成成"\$"
var aa = 18$ 转换成 aa = 18\$ aa.replace("\$","\\\$"); 注意JS的replace方法只能替换第一 ...
- AJPFX总结泛型概念和使用
泛型泛型(generic)概述和基本使用 泛型把明确数据类型的操作放到创建对象或者调用方法的时候再明确. J ...
- CF949A/950C Zebras
思路: 贪心乱搞. 实现: #include <bits/stdc++.h> using namespace std; vector<vector<int>> v; ...
- vue项目开发前的es6的知识储备
let命令 学习笔记 1.let所声明的变量,只在let命令所在的代码块内有效. 2.不存在变量提升:所声明的变量一定要在声明后使用,否则报错. 一定要先声明,再去使用.let x=x;这样就是错误的 ...
- ScrollView属性
1.文本内容过长,一个屏幕显示不下,这时候就把显示文本的 TextView包裹在ScrollView里面,可以做到滚动下滑查看的功能 2.隐藏滚动条 标签属性设置android:scrollbars= ...
- [Tunny]Grunt基础介绍
[黄映焜/Tunny,20140711] Grunt是一个JavaScript任务管理器,对于需要反复重复的任务,例如压缩.编译.单元测试.代码检查等,自动化工具可以减轻你的劳动,简化你的工作. 本文 ...
- Java序列化技术性能分析(JDK原生与Protostuff)
熟悉Java的朋友应该知道Java有一个叫序列化的技术,即把一个Object转换为可保存,可传输的流数据.相应的,同时存在反序列化,即将流数据转换为Object类,而在转换的过程中,该Object保持 ...
- 添加QScintilla时显示无法解析的外部函数
转载请注明出处:http://www.cnblogs.com/dachen408/p/7147165.html 问题:添加QScintilla时显示无法解析的外部函数 解决方案:去掉头文件qscisc ...