UVALive 6507 Passwords
2015-10-05 20:50
288 查看
Passwords
Time Limit: 3000msMemory Limit: 131072KB
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 = 205; const int base = 233; const int mod = 1e9+7; char str[maxn][20010]; LL hs[maxn][20010],B[20010]; int n; unordered_map<LL,int>ump; void init(){ B[0] = 1; for(int i = 1; i < 20010; ++i) B[i] = B[i-1]*base%mod; } LL calc(int i,int L,int R){ return ((hs[i][R] - hs[i][L-1]*B[R - L + 1])%mod + mod)%mod; } void solve(){ ump.clear(); for(int i = 0; i < n; ++i){ for(int j = 1,len = strlen(str[i] + 1); j <= len; ++j){ hs[i][j] = (hs[i][j-1]*base + str[i][j])%mod; ump[hs[i][j]]++; } } int a = 0,b = 0; for(int i = 0; i < n; ++i){ int len = strlen(str[i] + 1); for(int j = 1; j <= len; ++j) --ump[hs[i][j]]; for(int j = 1; j <= len; ++j){ LL suffix = calc(i,len - j + 1,len); if(!ump[suffix]) continue; int x = 1,y = 1; LL prefix = suffix; for(int k = 2; k*j <= len; ++k){ LL suffix2 = calc(i,len - j*k + 1,len); prefix = (prefix*B[j] + suffix)%mod; if(suffix2 != prefix) break; if(ump[prefix]) x = k; y = k; } if(x == y && x == 1) continue; if(x == y) --x; if(j*(x + y) > a + b){ a = x*j; b = y*j; } } for(int j = 1; 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 = 0; i < n; ++i) scanf("%s",str[i] + 1); solve(); } return 0; } /* 2 3 abcabe defg bcabab */
View Code
相关文章推荐
- 几种常见模式识别算法整理和总结(转)
- Ui 实现多线程的四种方式
- Cocos2d-x Box2D物理引擎编译设置
- React Native系列之-简介
- 连接数据库
- 对象——常用操作及方法
- 重载的定义
- Vim技巧5
- UI 多线程——种类
- Delphi应用程序的调试(1-10)
- [一个经典的多线程同步问题]总结
- UVa 1225 - Digit Counting【打表】
- 冒烟测试
- TreeSet对元素进行排序实现的两种方式
- 文本分类入门(一)文本分类问题的定义
- [Python进阶-5]类的特殊方法
- UVA 11991 Easy Problem from Rujia Liu?
- 简单0-1背包
- UITableView的优化问题
- 单向链表的建立(尾部插入法)