結果

問題 No.294 SuperFizzBuzz
ユーザー outlineoutline
提出日時 2021-02-22 15:53:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4,343 ms / 5,000 ms
コード長 1,899 bytes
コンパイル時間 1,651 ms
コンパイル使用メモリ 144,872 KB
実行使用メモリ 462,604 KB
最終ジャッジ日時 2023-10-21 11:13:16
合計ジャッジ時間 28,702 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 4,343 ms
462,324 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 223 ms
22,532 KB
testcase_09 AC 1,843 ms
233,424 KB
testcase_10 AC 2,777 ms
233,424 KB
testcase_11 AC 4,269 ms
286,200 KB
testcase_12 AC 4,189 ms
314,568 KB
testcase_13 AC 4,162 ms
329,216 KB
testcase_14 AC 4,229 ms
462,604 KB
権限があれば一括ダウンロードができます

ソースコード

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;

    auto check = [](const string& s, const string& t){
        if(s.length() != t.length())    return s.length() < t.length();
        return s < t;
    };
    for(int L = 3; L <= 25; ++L){
        priority_queue<string, vector<string>, decltype(check)> que(check);
        for(int i = 3; i <= L; i += 3){
            vector<int> perm(L - 1, 1);
            for(int j = 0; j < L - 1 - (i - 1); ++j)    perm[j] = 0;
            do {
                string s = "";
                for(int j = 0; j < L - 1; ++j){
                    s += perm[j] == 0 ? '3' : '5';
                }
                s += '5';
                que.emplace(s);
                if(que.size() > N)  que.pop();
            } while(next_permutation(begin(perm), end(perm)));
        }
        if(que.size() == N){
            cout << que.top() << endl;
            return 0;
        }
        N -= que.size();
    }

    return 0;
}
0