求助,样例都挂了,还没输入就RE了

P3796 AC 自动机(简单版 II)

@[寒炽·刻刻帝](/space/show?uid=49562) freopen没注释吧
by C3765428 @ 2019-08-24 10:47:55


```cpp for (rint i = 1; i <= n; i ++) cin >> s[i], ACA._Insert(s[i], i); // puts("FUCK"); ACA._Build(); // scanf("%s", s); cin.get(); //是不是之前输入了数字然后把换行符当作了p cin >> p; ```
by 一滴小水滴 @ 2019-08-24 10:48:12


无输入
by C3765428 @ 2019-08-24 10:50:01


话说您其他写的什么我啥也不知道,但是我经常跪在cin.get()上
by 一滴小水滴 @ 2019-08-24 10:50:06


@[C3765428](/space/show?uid=208240) @[一滴小水滴](/space/show?uid=182930) 不是这些锅。。我本地还没来得及输入就RE了
by tocek_shiki @ 2019-08-24 10:54:04


蛤?(大雾
by 一滴小水滴 @ 2019-08-24 10:54:42


@[寒炽·刻刻帝](/space/show?uid=49562) GDB是个好东西
by t162 @ 2019-08-24 11:00:00


@[寒炽·刻刻帝](/space/show?uid=49562) 问题出在`Aho_Corasick_Automaton::_Count(AC_Automaton < T, Size >, string);`里
by t162 @ 2019-08-24 11:06:03


@[Bambusoideae](/space/show?uid=106140) 是的啊,已经不RE了,然后WA on 样例了
by tocek_shiki @ 2019-08-24 11:07:25


现在的版本 ```cpp #include <bits/stdc++.h> #define Reg register #define rint Reg int #define fileread(a) freopen (a".in", "r", stdin), freopen(a".out", "w", stdout) using namespace std; template < class T > inline T read() { Reg T x = 0;Reg int f = 1;Reg char c; for (c = getchar(); !isdigit(c); c = getchar()) f = c=='-'?-1:f; for ( ; isdigit(c); c = getchar()) x = (x<<3)+(x<<1)+c-'0'; return f*x; } template < class T > inline void read(T &x){return x = read<T>(), (void)0;} #define MAXN 205 queue < int >q; namespace Aho_Corasick_Automaton { // template < class T > int __Ans[MAXN]; template < class T, int Size > class AC_Automaton { private: T __Id[Size]; T __Count[Size][26]; T __Val[Size]; T __Fail[Size]; T cnt; public: inline void _Clear(){memset(__Id, 0, sizeof (__Id)), memset(__Count, 0, sizeof(__Count)), memset(__Val, 0, sizeof (__Val)), memset(__Fail, 0, sizeof (__Fail)), cnt = 0;} AC_Automaton(){_Clear();} inline void _Insert(string s, int t) { rint len = s.size(); rint nw = 0; for (rint i = 0, v; i < len; i ++) { v = s[i]-'a'; if (!__Count[nw][v]) __Count[nw][v] = ++cnt; nw = __Count[nw][v]; } __Val[nw] ++; __Id[nw] = t; } inline void _Build() { for (rint i = 0; i < 26; i ++) if (__Count[0][i]) __Fail[__Count[0][i]] = 0, q.push(__Count[0][i]); while (!q.empty()) { rint u = q.front();q.pop(); for (rint i = 0; i < 26; i ++) if (__Count[u][i]) __Fail[__Count[u][i]] = __Count[__Fail[u]][i], q.push(__Count[u][i]); else __Count[u][i] = __Count[__Fail[u]][i]; } } inline T _Query(string s) { rint len = s.size(), nw = 0, res = 0; for (rint i = 0; i < len; i ++) { nw = __Count[nw][s[i]-'a']; for (rint t = nw; t && (~__Val[t]); t = __Fail[t]) res += __Val[t], __Val[t] = -1; } return res; } inline T _Get_Count (int _Position, int _Char) {return __Count[_Position][_Char];} inline T _Get_Fail (int _Position) {return __Fail[_Position];} // inline T _Get_Ans (int _Position) {return __Ans[_Position];} inline T _Get_Id (int _Position) {return __Id[_Position];} }; template < class T, int Size > inline void _Count(AC_Automaton < T, Size > AC, string s) { rint len = s.size(), nw = 0; for (rint i = 0; i < len; i ++) { // puts("FUCK"); nw = AC._Get_Count(nw, s[i]-'a'); for (rint t = nw; t; t = AC._Get_Fail(t)) __Ans[AC._Get_Id(t)] ++; } // return res; return ; } template < class T, int Size > inline T _find (AC_Automaton < T, Size > AC, int id) {return __Ans[id];} } Aho_Corasick_Automaton::AC_Automaton <int, 205> ACA; int n; string s[155]; string p; signed main() { while (read(n), n != 0) { ACA._Clear(); // read(n);2 for (rint i = 1; i <= n; i ++) cin >> s[i], ACA._Insert(s[i], i); ACA._Build(); cin >> p; Aho_Corasick_Automaton::_Count(ACA, p); rint ans = 0; for (rint i = 1; i <= n; i ++) if (ans < Aho_Corasick_Automaton::__Ans[i]) ans = Aho_Corasick_Automaton::__Ans[i]; printf ("%d\n", ans); for (rint i = 1; i <= n; i ++) if (ans == Aho_Corasick_Automaton::__Ans[i]) cout << s[i] << "\n"; } return 0; } ```
by tocek_shiki @ 2019-08-24 11:08:38


| 下一页