• Source
    1. /**************************************************************
    2.   Problem: 1526
    3.   User: zrts
    4.   Language: C++
    5.   Result: Accepted
    6.   Time:1348 ms
    7.   Memory:11060 kb
    8. ****************************************************************/
    9.  
    10. #include<cstdio>
    11. #include<cstring>
    12. #include<algorithm>
    13. //by zrt
    14. //problem:
    15. //无论你在什么时候开始,重要的是开始以后就不要停止。
    16. using namespace std;
    17. typedef long long ll;
    18. const double eps(1e-10);
    19. const int inf(0x7fffffff);
    20. int last[10005][10];//>=
    21. char s[1005][10005];
    22. int num[1005];
    23. int tot[10050];
    24. int ans,n;
    25. int main(){
    26. #ifdef LOCAL
    27. freopen("in.txt","r",stdin);
    28. freopen("out.txt","w",stdout);
    29. #endif
    30. scanf("%d",&n);
    31. for(int i=0;i<n;i++){
    32. scanf("%d%s",&num[i],s[i]);
    33. }
    34. for(int i=0;i<n;i++){
    35. for(int j=0;j<10;j++) last[num[i]][j]=-1;
    36. for(int j=num[i]-1;j>=0;j--){
    37. for(int k=0;k<10;k++) last[j][k]=last[j+1][k];
    38. last[j][s[i][j]-'0']=j;
    39. }
    40. for(int p=0;p<10000;p++){
    41. if(tot[p]<i) continue;
    42. bool ok=1;
    43. int idx=0;
    44. if(last[idx][p/1000]!=-1){
    45. idx=last[idx][p/1000];
    46. }else {
    47. ok=0;
    48. }
    49. if(last[idx][p/100%10]!=-1){
    50. idx=last[idx][p/100%10];
    51. }else {
    52. ok=0;
    53. }
    54. if(last[idx][p/10%10]!=-1){
    55. idx=last[idx][p/10%10];
    56. }else {
    57. ok=0;
    58. }
    59. if(last[idx][p%10]!=-1){
    60. idx=last[idx][p%10];
    61. }else {
    62. ok=0;
    63. }
    64. if(ok) tot[p]++;
    65. }
    66. }
    67. for(int i=0;i<10000;i++){
    68. if(tot[i]==n) ans++;
    69. }
    70. printf("%d\n",ans);
    71. return 0;
    72. }