hack数据过不了的特殊判断一下

P2580 于是他错误的点名开始了

@[Sakuya_maid](/user/817442) 大佬有点不太懂这个hack数据相对于其他卡的是什么地方(一头雾水)
by HalfMonkey @ 2023-04-09 21:49:52


@[HalfMonkey](/user/901221) ```c #include<bits/stdc++.h> using namespace std; const int N=1e6+5; int son[N][27],idx; string s; int n,m; struct op { int cnt; bool flag; }a[N]; int getnum(char c) { return c-'a'; } void insert() { int p=0; for(int i=0;s[i];i++) { int u = getnum(s[i]); if(!son[p][u]) son[p][u] = ++idx; p = son[p][u]; } a[p].cnt++; } void query() { int p=0; for(int i=0;s[i];i++) { int u = getnum(s[i]); if(!son[p][u]){ cout << "WRONG" << '\n'; return; }else{ p = son[p][u]; } } if(a[p].cnt==0){ cout << "WRONG" << '\n'; return ; } if(!a[p].flag){ a[p].flag=1; cout << "OK" << '\n'; return; }else if(a[p].flag){ cout << "REPEAT" << '\n'; return; } } int main() { cin.tie(nullptr)->sync_with_stdio(false); std::cin.tie(0); std::ios::sync_with_stdio(false); cin >> n; for(int i=1;i<=n;i++) { cin >> s; insert(); } cin >> m; for(int i=1;i<=m;i++) { cin >> s; query(); } } ``` 这是我的完整代码,就是往回溯的时候找这是不是一句完整的不是前缀相同的名字,去掉的话有可能是前缀相等也输出OK了,与题意冲突,还有,我是蒟蒻www
by Sakuya_maid @ 2023-04-12 16:11:02


|