fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <map>
  5. #include <chrono>
  6.  
  7. typedef std::vector<std::uint64_t> DType;
  8. typedef std::vector<DType> RType;
  9. typedef std::map <std::uint64_t, bool> SType;
  10.  
  11. DType MakeInit(std::uint64_t N){
  12. std::uint64_t i = N;
  13. DType D;
  14. for (std::size_t i = 1; i <= N; i++)
  15. {
  16. D.push_back(1);
  17. }
  18. return D;
  19. }
  20.  
  21. bool AddRadix(DType& D, std::uint64_t R){
  22. bool Carry = false;
  23. D[0]++;
  24. for (std::size_t i = 0; i < D.size(); i++)
  25. {
  26. if (Carry == true){
  27. D[i]++;
  28. }
  29. Carry = false;
  30.  
  31. if (D[i] > R){
  32. D[i] = 1;
  33. Carry = true;
  34. }
  35. }
  36. return true;
  37. }
  38.  
  39. bool check(DType& D, std::uint64_t Max){
  40. SType M;
  41. std::uint64_t V = 0;
  42.  
  43. for (std::size_t k = 1; k <= D.size(); k++){
  44. for (std::size_t i = 0; i < D.size(); i++){
  45. for (std::size_t j = 0; j < k; j++){
  46. auto Idx = (i + j) % D.size();
  47. V += D[Idx];
  48. }
  49. M[V] = true;
  50. V = 0;
  51. }
  52. }
  53. for (std::uint64_t i = 1; i <= Max; i++){
  54. if (M[i] == false) return false;
  55. }
  56. return true;
  57. }
  58.  
  59. RType MakeHoge(std::uint64_t N = 5, std::uint64_t R = 21 - 5,std::uint64_t M =21){
  60. DType D = MakeInit(N);
  61. bool F = false;
  62. RType Re;
  63.  
  64. while (F == false){
  65. if (check(D,M) == true){
  66. Re.push_back(D);
  67. }
  68. AddRadix(D, R);
  69.  
  70. F = true;
  71. for (std::size_t i = 0; i < D.size(); i++){
  72. if (D[i] != R){
  73. F = false;
  74. break;
  75. }
  76. }
  77. }
  78.  
  79.  
  80. return Re;
  81.  
  82. }
  83.  
  84. bool Show(RType& R){
  85.  
  86. for (auto& oo : R){
  87. std::cout << '[';
  88. for (auto& o : oo){
  89. std::cout << o<<',';
  90. }
  91. std::cout << ']' << std::endl;
  92. }
  93.  
  94. return true;
  95. }
  96. int main(){
  97. std::uint64_t N = 5;
  98. std::uint64_t R = 10;//>>893の結果を観た結果論。
  99. RType Re;
  100.  
  101. auto S = std::chrono::high_resolution_clock::now();
  102. Re = MakeHoge(N, R, 21);
  103. Show(Re);
  104. auto E = std::chrono::high_resolution_clock::now();
  105.  
  106. auto El = std::chrono::duration_cast<std::chrono::milliseconds >(E - S);
  107.  
  108. std::cout << "Time Using:" << El.count() << "ms" << std::endl;
  109.  
  110. return 0;
  111.  
  112. }
Success #stdin #stdout 0.38s 3236KB
stdin
Standard input is empty
stdout
[5,2,10,3,1,]
[3,10,2,5,1,]
[10,3,1,5,2,]
[5,1,3,10,2,]
[10,2,5,1,3,]
[1,5,2,10,3,]
[2,10,3,1,5,]
[1,3,10,2,5,]
[3,1,5,2,10,]
[2,5,1,3,10,]
Time Using:384ms