记录编号 199268 评测结果 AAAAAAAAAA
题目名称 解密牛语 最终得分 100
用户昵称 Gravatar张灵犀不和我一般见识真可怕呢(笑 是否通过 通过
代码语言 C++ 运行时间 1.661 s
提交时间 2015-10-26 15:14:10 内存使用 1.27 MiB
显示代码纯文本
  1. #include<cstdio>
  2. #include<string>
  3. #include<iostream>
  4. using namespace std;
  5. const int MOD=1000003;
  6. typedef long long LL;
  7. string E="\0";
  8. string txt;
  9. int C=0,O=0,W=0,S=0,T,End=0;
  10. bool h[MOD]={0};
  11. void read()
  12. {
  13. E="Begin the Escape ex";
  14. E+="ecution at the Break of Dawn";
  15. getline(cin,txt);
  16. }
  17. int BKDhash(string A)
  18. {
  19. LL seed=131313;
  20. LL ans=0;
  21. for(int i=0;i<A.size();i++)
  22. {
  23. ans+=ans*seed+(int)A[i];
  24. ans%=MOD;
  25. }
  26. return ans%MOD;
  27. }
  28. string change(string A,int c,int o,int w)
  29. {
  30. string ans;
  31. for(int i=0;i<c;i++) ans+=A[i];
  32. for(int i=o+1;i<w;i++) ans+=A[i];
  33. for(int i=c+1;i<o;i++) ans+=A[i];
  34. for(int i=w+1;i<A.size();i++) ans+=A[i];
  35. return ans;
  36. }
  37. bool legal(string A)
  38. {
  39. int lens=A.size(),len=0,i=0;
  40. while(len<lens&&A[len]!='C')
  41. {
  42. if(A[len]!=E[len]) return 0;
  43. len++;
  44. }
  45. int st=len,ed;
  46. i=E.size()-1;len=A.size()-1;
  47. while(i>=0&&len>=0&&A[len]!='W')
  48. {
  49. if(A[len]!=E[i]) return 0;
  50. len--,i--;
  51. }
  52. ed=len;
  53. while(st<ed)
  54. {
  55. string now;
  56. st++;
  57. bool flag=0;
  58. while(st<ed&&A[st]!='C'&&A[st]!='O'&&A[st]!='W')
  59. {
  60. now+=A[st];
  61. st++;
  62. }
  63. if(now.size()==0) flag=1;
  64. //cout<<A<<" "<<now<<endl;
  65. for(int j=0;j<E.size()-now.size();j++)
  66. {
  67. for(int k=j;k<j+now.size();k++)
  68. {
  69. if(E[k]!=now[k-j]) break;
  70. if(k==j+now.size()-1) flag=1;
  71. }
  72. if(flag==1) break;
  73. }
  74. if(flag==0) return 0;
  75. }
  76. return 1;
  77. }
  78. bool pan(string now)
  79. {
  80. bool flag=0;
  81. if(now.size()==0) flag=1;
  82. for(int j=0;j<=E.size()-now.size();j++)
  83. {
  84. for(int k=j;k<j+now.size();k++)
  85. {
  86. if(E[k]!=now[k-j]) break;
  87. if(k==j+now.size()-1) flag=1;
  88. }
  89. if(flag==1) break;
  90. }
  91. //cout<<now<<" "<<flag<<endl;
  92. if(flag==0) return 0;
  93. return 1;
  94. }
  95. string get(string A,int p,int q)
  96. {
  97. int i=p;
  98. int st=i-1;
  99. int len=A.size();
  100. while(st>=0&&A[st]!='C'&&A[st]!='O'&&A[st]!='W') st--;
  101. st++;
  102. string ans;
  103. for(int j=st;j<i;j++) ans+=A[j];
  104. st=q+1;
  105. while(st<len&&A[st]!='C'&&A[st]!='O'&&A[st]!='W')
  106. {
  107. ans+=A[st];
  108. st++;
  109. }
  110. return ans;
  111. }
  112. bool check(string A,int c,int o,int w)
  113. {
  114. int len=A.size();
  115. string ans;
  116. ans=get(A,c,o);if(!pan(ans)) return 0;
  117. ans=get(A,o,w);if(!pan(ans)) return 0;
  118. ans=get(A,w,c);if(!pan(ans)) return 0;
  119. //cout<<ans<<endl;
  120. return 1;
  121. }
  122. bool dfs(string A,int step)
  123. {
  124. string now;
  125. //cout<<A<<" "<<step<<endl;
  126. int Hash=BKDhash(A);
  127. if(h[Hash]) return 0;
  128. else if(A==E)
  129. {
  130. cout<<1<<" "<<step<<endl;
  131. return 1;
  132. }
  133. h[Hash]=1;
  134. if(!legal(A)) return 0;
  135. for(int o=0;o<A.size();o++)
  136. {
  137. if(A[o]!='O') continue;
  138. for(int c=0;c<o;c++)
  139. {
  140. if(A[c]!='C') continue;
  141. for(int w=A.size()-1;w>o;w--)
  142. {
  143. if(A[w]!='W') continue;
  144. string now;
  145. //cout<<A<<" "<<c<<" "<<o<<" "<<w<<endl;
  146. if(!check(A,c,o,w)) continue;
  147. now=change(A,c,o,w);
  148. //cout<<now<<endl;
  149. //cout<<endl;
  150. if(dfs(now,step+1)) return 1;
  151. }
  152. }
  153. }
  154. return 0;
  155. }
  156. void work()
  157. {
  158. End=BKDhash(E);
  159. //cout<<End<<endl;
  160. if((txt.size()-E.size())%3!=0||!dfs(txt,0)) printf("0 0\n");
  161. }
  162. int main()
  163. {
  164. freopen("cryptcow.in","r",stdin);
  165. freopen("cryptcow.out","w",stdout);
  166. read();
  167. work();
  168. return 0;
  169. }