fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <cmath>
  5. #include <iomanip>
  6. #include <tuple>
  7.  
  8. typedef std::vector<std::vector<std::uint64_t>> DType;
  9. typedef std::tuple<DType, std::uint64_t, std::uint64_t, std::uint64_t> RType;
  10.  
  11. DType MakeVector(std::size_t N){
  12. DType R(N);
  13.  
  14. for (auto& o : R)o.resize(N);
  15.  
  16. return R;
  17. }
  18. bool Show(RType& R){
  19. std::cout << "Result:Call = " << std::get<1>(R) << " Accept = " << std::get<2>(R)<<"*"<<std::get<2>(R) << " Moded@ " << std::get<3>(R) << "Count!!" << std::endl;
  20.  
  21. for (auto& oo : std::get<0>(R)){
  22. for (auto& o : oo){
  23. std::cout << std::setw(3) << std::left << o << ' ';
  24. }
  25. std::cout << std::endl;
  26. }
  27. return true;
  28. }
  29. bool RollingThunder(DType& D, std::uint64_t N){
  30.  
  31. std::int64_t X = 0, Y = 0;
  32. std::int64_t i = 1;
  33. std::int64_t L = 0, R = 0, U = 0, B = 0;
  34.  
  35. while (i <= N){
  36. for (X = L; X < (D[Y].size() - R); X++, i++) D[Y][X] = i;
  37. U++;
  38. X=(D[Y].size() - R)-1;
  39. for (Y = U; Y < (D.size() - B); Y++, i++)D[Y][X] = i;
  40. R++;
  41. Y=(D.size() - B)-1;
  42. for (X=(D[Y].size() - R)-1; X >=L; X--, i++) D[Y][X] = i;
  43. B++;
  44. X=L;
  45. for (Y=(D.size() - B)-1; Y >=U; Y--, i++) D[Y][X] = i;
  46. L++;
  47. Y=U;
  48. //Show(D);
  49. }
  50. return true;
  51. }
  52.  
  53. RType MakeHoge(std::uint64_t N){
  54. std::uint64_t X = std::sqrt(N);
  55. if (X % 2 == 0) X--;
  56. std::uint64_t Y = N - (X*X);
  57. DType D = MakeVector(X);
  58.  
  59. RollingThunder(D, X*X);
  60.  
  61. return std::make_tuple(D,N,X,Y);
  62. }
  63.  
  64.  
  65.  
  66. int main(){
  67. RType R;
  68. std::uint64_t N;
  69.  
  70. std::cin >> N;
  71.  
  72. R = MakeHoge(N);
  73. Show(R);
  74.  
  75. return 0;
  76. }
Success #stdin #stdout 0s 3480KB
stdin
123
stdout
Result:Call = 123 Accept = 11*11 Moded@ 2Count!!
1   2   3   4   5   6   7   8   9   10  11  
40  41  42  43  44  45  46  47  48  49  12  
39  72  73  74  75  76  77  78  79  50  13  
38  71  96  97  98  99  100 101 80  51  14  
37  70  95  112 113 114 115 102 81  52  15  
36  69  94  111 120 121 116 103 82  53  16  
35  68  93  110 119 118 117 104 83  54  17  
34  67  92  109 108 107 106 105 84  55  18  
33  66  91  90  89  88  87  86  85  56  19  
32  65  64  63  62  61  60  59  58  57  20  
31  30  29  28  27  26  25  24  23  22  21