#include <iostream> #include <vector> #include <cstdint> #include <map> #include <chrono> typedef std::vector<std::uint64_t> DType; typedef std::vector<DType> RType; typedef std::map <std::uint64_t, bool> SType; DType MakeInit(std::uint64_t N){ std::uint64_t i = N; DType D; for (std::size_t i = 1; i <= N; i++) { D.push_back(1); } return D; } bool AddRadix(DType& D, std::uint64_t R){ bool Carry = false; D[0]++; for (std::size_t i = 0; i < D.size(); i++) { if (Carry == true){ D[i]++; } Carry = false; if (D[i] > R){ D[i] = 1; Carry = true; } } return true; } bool check(DType& D, std::uint64_t Max){ SType M; std::uint64_t V = 0; for (std::size_t k = 1; k <= D.size(); k++){ for (std::size_t i = 0; i < D.size(); i++){ for (std::size_t j = 0; j < k; j++){ auto Idx = (i + j) % D.size(); V += D[Idx]; } M[V] = true; V = 0; } } for (std::uint64_t i = 1; i <= Max; i++){ if (M[i] == false) return false; } return true; } RType MakeHoge(std::uint64_t N = 5, std::uint64_t R = 21 - 5,std::uint64_t M =21){ DType D = MakeInit(N); bool F = false; RType Re; while (F == false){ if (check(D,M) == true){ Re.push_back(D); } AddRadix(D, R); F = true; for (std::size_t i = 0; i < D.size(); i++){ if (D[i] != R){ F = false; break; } } } return Re; } bool Show(RType& R){ for (auto& oo : R){ std::cout << '['; for (auto& o : oo){ std::cout << o<<','; } std::cout << ']' << std::endl; } return true; } int main(){ std::uint64_t N = 5; std::uint64_t R = 10;//>>893の結果を観た結果論。 RType Re; auto S = std::chrono::high_resolution_clock::now(); Re = MakeHoge(N, R, 21); Show(Re); auto E = std::chrono::high_resolution_clock::now(); auto El = std::chrono::duration_cast<std::chrono::milliseconds >(E - S); std::cout << "Time Using:" << El.count() << "ms" << std::endl; return 0; }
Standard input is empty
[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