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
*/

UVALive 6507 Passwords的更多相关文章

  1. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  2. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  3. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  4. 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 ...

  5. codeforces 721B B. Passwords(贪心)

    题目链接: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  7. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  8. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  9. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

随机推荐

  1. 贪心 UVALive 6832 Bit String Reordering

    题目传送门 /* 贪心:按照0或1开头,若不符合,选择后面最近的进行交换.然后选取最少的交换次数 */ #include <cstdio> #include <algorithm&g ...

  2. how-to-fix-fs-re-evaluating-native-module-sources-is-not-supported-graceful

    http://stackoverflow.com/questions/37346512/how-to-fix-fs-re-evaluating-native-module-sources-is-not ...

  3. sqlserver 使用database mail 发送邮件

    EXEC sp_send_dbmail @profile_name='dbmaster@zhidiansoft.net',@recipients='xxxxxxx@qq.com',@subject=' ...

  4. get和post中文乱码原理相关博客

    博客一:  http://blog.csdn.net/saygoodbyetoyou/article/details/16834395 博客二: http://www.jb51.net/article ...

  5. android开发学习——Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/zxing/BarcodeFormat;

    在Android Studio中,sync project没有错,但是run时会报错; http://blog.csdn.net/q568430333/article/details/50969033 ...

  6. mysql之通过cmd连接远程数据库

    ---恢复内容开始--- 目录 前提 连接远程数据库 前提: 本地安装了mysql数据库 本地和远程网络是连通的,通过命令ping ip (即ping 192.168.0.333),可以ping通 连 ...

  7. Kickstart Round D 2017 : A

    思路: 动态规划. large数据的时间范围很大,无法设计入状态中.转换思路为定义dp[i][j]为当前在景点i,并且已经游览了j个景点所花费的最小时间,这种思想与leetcode45类似.于是转移方 ...

  8. git push代码时的'git did not exit cleanly (exit code 1)'问题解决

    在利用git管理本地发布的galleryLeftOrRight插件项目时,按照git的使用方法:先commit→master,再 push,发现提示错误git did not exit cleanly ...

  9. web.xml 加载顺序

    参考网址: 上下文对象>监听>过滤器>servlet 1.先加载上下文对象 <!-- 初始化Spring classpath*:spring/applicationContex ...

  10. 【PostgreSQL-9.6.3】一般视图

    PG视图分为两种,一种是物化视图,一种是一般视图.本篇文章主要写一般视图哪些事儿.所谓一般视图,通俗点说,就是由查询语句定义的虚拟表.视图中的数据可能来自一张或多张表. 1. 视图创建语句 CREAT ...