結果

問題 No.2118 遺伝的有限集合の数え上げ
ユーザー 👑 p-adic
提出日時 2022-09-14 22:48:17
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 764 bytes
コンパイル時間 996 ms
コンパイル使用メモリ 71,124 KB
最終ジャッジ日時 2025-02-07 05:24:36
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <stdio.h>
#include <stdint.h>
using namespace std;

using uint = unsigned int;

#define CIN( LL , A ) LL A; cin >> A 
#define RETURN( ANSWER ) cout << ( ANSWER ) << endl; return 0 

#include <cassert>

const string& EnumerateHereditarilyFiniteSets( const uint& n )
{
  static string s[1000001] = {};
  string& sn = s[n];  
  if( sn != "" ){
    return sn;
  }
  uint n_copy = n;
  uint i = 0;
  while( n_copy != 0 ){
    if( n_copy % 2 == 1 ){
      sn += "," + EnumerateHereditarilyFiniteSets( i );
    }
    n_copy /= 2;
    i++;
  }
  sn = "{" + ( sn == "" ? sn : sn.substr( 1 ) ) + "}";
  return sn;
}

int main()
{
  CIN( uint , N );
  assert( N <= 1000000 );
  RETURN( EnumerateHereditarilyFiniteSets( N ) );
}
0