結果

問題 No.294 SuperFizzBuzz
ユーザー ともきともき
提出日時 2015-11-19 10:56:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 105 ms / 5,000 ms
コード長 3,889 bytes
コンパイル時間 1,163 ms
コンパイル使用メモリ 122,212 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 18:03:24
合計ジャッジ時間 2,735 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 105 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 67 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 86 ms
4,352 KB
testcase_12 AC 95 ms
4,348 KB
testcase_13 AC 99 ms
4,352 KB
testcase_14 AC 105 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cassert>

#include <unordered_set>
#include <unordered_map>
#include <random>
#include <thread>
#include <chrono>

using namespace std;

#define int long long
#define let const auto
#define var auto

#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define for_by_size(i,v) repeat(i, v.size())
#define debug(x) #x << "=" << (x)


#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x) 
#endif

typedef complex<double> point;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    for(auto it = v.begin(); it != v.end(); ++it){
        if(it != v.begin()){
            os << ",";
        }
        os << *it;
    }
    return os << "}";
}
template<typename T>
void isort(std::vector<T>& v, std::function<bool(T,T)> comp=less<T>()){
    sort(v.begin(), v.end(), comp);
}

template<typename T>
std::vector<T> sort(std::vector<T> v, std::function<bool(T,T)> comp=less<T>()){
    isort(v);
    return v;
}
template<typename T1, typename T2>
std::vector<T2> rmap(const std::vector<T1>& v, std::function<T2(T1)> f){
    std::vector<T2> t; t.reserve(v.size());
    for(const auto& i: v) t.push_back(f(i));
    return t;
}
std::vector<std::string> split(std::string str, char delim){
    std::vector<std::string> res;
    size_t current = 0, found;
    while((found = str.find_first_of(delim, current)) != std::string::npos){
        res.push_back(std::string(str, current, found - current));
        current = found + 1;
    }
    res.push_back(std::string(str, current, str.size() - current));
    return res;
}
string join(const std::vector<string>& v, string delim){
    string ret = "";
    for(auto it = v.begin(); it != v.end(); ++it){
        if(it != v.begin()){
            ret += delim;
        }
        ret += *it;
    }
    return ret;
}


int nCr(int n, int r){
    if(n < r) return 0;
    if(r > n-r) return nCr(n,n-r);
    int ret = 1;
    for(int i=0;i<r;i++){
        ret *= n-i;
        ret /= (i+1);
    }
    return ret;
}

// # name: popcount
// # key: popcount
// # 立っているビットの数を数える
// # --
template<typename T>
int popcount(T x){
    int ret = 0;
    while(x){
        x &= x-1;
        ret++;
    }
    return ret;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);


    int n; cin >> n;
    vector<int> cat_by_k(30);
    repeat(k, cat_by_k.size()){
        if(k == 0) continue;
        int fm = k - 1;
        for(int i=2; i <= fm;i+=3){
            cat_by_k[k] += nCr(fm,i);
        }
    }
    vector<int> cat_below(cat_by_k.size()+1);
    for(int i=1;i<cat_below.size();i++){
        cat_below[i] = cat_below[i-1] + cat_by_k[i-1];
    }
    int where_is_n = -1;
    repeat(k, cat_below.size()){
        if(n <= cat_below[k]){
            where_is_n = k-1;
            break;
        }
    }
    assert(where_is_n != -1);
    n -= cat_below[where_is_n];
    for(int mask = 1;;mask += 2){
        if(popcount(mask-1) % 3 == 2){
            n--;
            if(n == 0){
                string out = "";
                for(int i=0;i<where_is_n;i++){
                    if(mask & (1 << i)){
                        out += '5';
                    }else{
                        out += '3';
                    }
                }
                reverse(all(out));
                cout << out << endl;
                return 0;
            }
        }
    }


    return 0;
}
0