fork(1) download
  1. #include <bits/stdc++.h>
  2. #include "messy.h"
  3. using namespace std;
  4.  
  5. void find_writes(string s0, vector<int> Bq) {
  6. int n =s0.length(), q =Bq.size();
  7. if(q == 1) return;
  8. for(int i =0; i < q/2; i++) {
  9. string s =s0;
  10. s[Bq[i]] ='1';
  11. add_element(s);}
  12. string s1 =s0, s2 =s0;
  13. vector<int> Bq1,Bq2;
  14. for(int i =0; i < q/2; i++) {
  15. s1[Bq[i]] ='1';
  16. Bq2.push_back(Bq[i]);}
  17. for(int i =0; i < q/2; i++) {
  18. s2[Bq[q/2+i]] ='1';
  19. Bq1.push_back(Bq[q/2+i]);}
  20. find_writes(s1,Bq1);
  21. find_writes(s2,Bq2);}
  22.  
  23. void find_perm(string s0, vector<int> Bq, vector<int> Bres, vector<int> &P) {
  24. int n =s0.length(), q =Bq.size();
  25. /* for(int i =0; i < q; i++) cout << Bq[i] << " ";
  26. cout << "\n";
  27. for(int i =0; i < q; i++) cout << Bres[i] << " ";
  28. cout << ".\n";
  29. */ if(q == 2) {
  30. string s =s0;
  31. s[Bres[0]] ='1';
  32. if(check_element(s)) {
  33. P[Bres[0]] =Bq[0];
  34. P[Bres[1]] =Bq[1];}
  35. else {
  36. P[Bres[0]] =Bq[1];
  37. P[Bres[1]] =Bq[0];}
  38. return;}
  39. vector<int> Bres1,Bres2;
  40. for(int i =0; i < q; i++) {
  41. string s =s0;
  42. s[Bres[i]] ='1';
  43. if(check_element(s)) Bres1.push_back(Bres[i]);
  44. else Bres2.push_back(Bres[i]);}
  45. vector<int> Bq1,Bq2;
  46. string s1 =s0, s2 =s0;
  47. for(int i =0; i < q/2; i++) Bq2.push_back(Bq[q/2+i]);
  48. for(int i =0; i < q/2; i++) Bq1.push_back(Bq[i]);
  49. for(int i =0; i < q/2; i++) s2[Bres1[i]] =s1[Bres2[i]] ='1';
  50. find_perm(s1,Bq1,Bres1,P);
  51. find_perm(s2,Bq2,Bres2,P);}
  52.  
  53. vector<int> restore_permutation(int n, int w, int r) {
  54. int b =0;
  55. while((1<<b) != n) b++;
  56.  
  57. vector<int> Bq;
  58. string s0;
  59. for(int i =0; i < n; i++) {
  60. Bq.push_back(i);
  61. s0 +="0";}
  62. find_writes(s0,Bq);
  63.  
  64. compile_set();
  65.  
  66. vector<int> P(n);
  67. find_perm(s0,Bq,Bq,P);
  68.  
  69. return P;}
  70.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:19: fatal error: messy.h: No such file or directory
compilation terminated.
stdout
Standard output is empty