Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
重点是input的最后一句...开始以为是输入文件不超过16M...各种hash取模+set各种TLE... 后来发现意思是子串hash后的值不超过16M..开个16M的bool数组就好..hash也简单多了 常规操作 #include<cstdio> int ha[266], n, i, j, z, ans, te, mm; bool ch[266], x[16000006]; char ss[688888]; int main() { scanf("%d%*d%s", &n, ss); z = ans = mm = 1; for (; ss[j]; j++) if (!ch[ss[j]]) ch[ss[j]] = 1, ha[ss[j]] = z++; for (; i < n; i++) te *= z, te += ha[ss[i]], mm *= z; for (x[te] = 1, mm /= z; i < j; i++) { te %= mm, te *= z, te += ha[ss[i]]; if (!x[te]) x[te] = 1, ans++; } printf("%d\n", n < j ? ans : 0); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator