fork download
  1. /*
  2. ID: untamed
  3. PROG: Numeric sequences
  4. LANG: C++
  5. */
  6.  
  7. #include<cstdio>
  8. #include<iostream>
  9. #include<algorithm>
  10. #include<string>
  11. #include<cstring>
  12. #include<vector>
  13. #include<stack>
  14. #include<queue>
  15. #include<deque>
  16. #include<map>
  17. #include<set>
  18. #include<limits>
  19. #include<climits>
  20. #include<cmath>
  21. #include<functional>
  22. #include<ctime>
  23. #include<cstdlib>
  24. #include<fstream>
  25. #include<typeinfo>
  26.  
  27. using namespace std;
  28.  
  29. typedef long long int ll;
  30. typedef short int i16;
  31. typedef unsigned long long int u64;
  32. typedef unsigned int u32;
  33. typedef unsigned short int u16;
  34. typedef unsigned char u8;
  35.  
  36. const int N = 1<<17;
  37.  
  38. int first[N],second[N],third[N];//Here I store the number of occurrences of each number in each column
  39.  
  40. bool here[N];//here[i] is true if we haven't removed the i-th column yet
  41.  
  42. int a[4][N];
  43.  
  44. int n;
  45.  
  46. void input() {
  47. scanf("%d", &n);
  48. int i;
  49. for(i=1;i<=n;i++) {
  50. scanf("%d", &a[1][i]);
  51. first[a[1][i]]++;
  52. }
  53. for(i=1;i<=n;i++) {
  54. scanf("%d", &a[2][i]);
  55. second[a[2][i]]++;
  56. }
  57. for(i=1;i<=n;i++) {
  58. scanf("%d", &a[3][i]);
  59. third[a[3][i]]++;
  60. }
  61. for(i=1;i<=n;i++) {
  62. here[i]=true;
  63. }
  64. }
  65.  
  66. void solve() {
  67. int i;
  68. int ans=0;
  69. bool action=true;
  70. while(action==true) {
  71. action=false;
  72. for(i=1;i<=n;i++) {
  73. if(here[i]==false) //Removed
  74. continue;
  75. if(second[a[1][i]]==0 || third[a[1][i]]==0
  76. || first[a[2][i]]==0 || third[a[2][i]]==0
  77. || first[a[3][i]]==0 || second[a[3][i]]==0) { //Forced column
  78. ans++;
  79. action=true;
  80. here[i]=false;
  81. first[a[1][i]]--;
  82. second[a[2][i]]--;
  83. third[a[3][i]]--;
  84. }
  85. }
  86. }
  87. printf("%d\n", ans);
  88. }
  89.  
  90. int main() {
  91. input();
  92. solve();
  93. return 0;
  94. }
  95.  
Success #stdin #stdout 0s 6856KB
stdin
Standard input is empty
stdout
0