记录编号 203101 评测结果 AAAAAAAAAA
题目名称 [SYOI 2015] Asm.Def谈笑风生 最终得分 100
用户昵称 Gravatarfyb 是否通过 通过
代码语言 C++ 运行时间 0.555 s
提交时间 2015-11-02 16:23:22 内存使用 0.31 MiB
显示代码纯文本
  1. #include <cstdio>
  2. #include <vector>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. #define MMAX 100000
  8. #define LMAX 20
  9. #define NUM 26
  10.  
  11. struct node{
  12. int s[NUM];
  13. bool v[NUM];
  14. };
  15.  
  16. vector<node> tire;
  17. char ts[LMAX+1];
  18. node nd0;
  19.  
  20. bool dfs(int pt,int tp,int lents){
  21. if(tp==lents-1)return tire[pt].v[ts[tp]-'a'];
  22. else if(!tire[pt].s[ts[tp]-'a'])return false;
  23. else return dfs(tire[pt].s[ts[tp]-'a'],tp+1,lents);
  24. }
  25.  
  26. int main(){
  27. int m;
  28. int tt,tl;
  29. bool fndx,fnde;
  30. int pt;
  31. int i,j,k;
  32.  
  33. freopen("asm_talk.in","r",stdin);
  34. freopen("asm_talk.out","w",stdout);
  35.  
  36. scanf("%d",&m);
  37. tire.push_back(nd0);
  38. for(i=0;i<m;i++){
  39. scanf("%d%s",&tt,ts);
  40. tl=strlen(ts);
  41. if(tt==1){
  42. pt=0;
  43. for(j=0;ts[j+1]!='\0';j++){
  44. if(!tire[pt].s[ts[j]-'a']){
  45. tire[pt].s[ts[j]-'a']=tire.size();
  46. tire.push_back(nd0);
  47. }
  48. pt=tire[pt].s[ts[j]-'a'];
  49. }
  50. tire[pt].v[ts[j]-'a']=true;
  51. }else{
  52. fndx=false;
  53. for(j=0;j<tl;j++)
  54. if(ts[j]=='*'){
  55. fndx=true;
  56. fnde=false;
  57. for(k=0;k<NUM;k++){
  58. ts[j]='a'+k;
  59. if(dfs(0,0,tl)){
  60. printf("YES\n");
  61. fnde=true;
  62. break;
  63. }
  64. }
  65. if(!fnde)printf("NO\n");
  66. }
  67. if(!fndx)printf(dfs(0,0,tl)?"YES\n":"NO\n");
  68. }
  69. }
  70. return 0;
  71. }
  72.