結果

問題 No.294 SuperFizzBuzz
ユーザー outline
提出日時 2021-02-22 16:10:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,559 ms / 5,000 ms
コード長 1,737 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 134,764 KB
最終ジャッジ日時 2025-01-19 03:32:10
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    priority_queue<pair<int, int>> que;
    for(int mask = 1; mask < 1 << 25; ++mask){
        if((__builtin_popcount(mask) % 3 == 0) && (mask % 2 == 1)){
            int msb = 25;
            for(int k = 24; k >= 0; --k){
                if(mask >> k & 1){
                    msb = k;
                    break;
                }
            }
            for(int i = msb + 1; i <= 25; ++i){
                que.emplace(i, mask);
                if(que.size() > N)  que.pop();
            }
        }
    }

    int d = que.top().first, mask = que.top().second;
    string ans = "";
    for(int i = 0; i < d; ++i){
        ans += (mask >> i & 1) ? '5' : '3';
    }
    reverse(begin(ans), end(ans));
    cout << ans << endl;

    return 0;
}
0