結果

問題 No.294 SuperFizzBuzz
ユーザー firiexpfiriexp
提出日時 2019-12-27 09:29:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,701 bytes
コンパイル時間 960 ms
コンパイル使用メモリ 101,248 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-09 21:20:02
合計ジャッジ時間 1,922 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <limits>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n;
    cin >> n;
    int M = 30;
    auto dp = make_v(M+1, 3, 2, 0);
    dp[0][2][1] = 1;
    for (int i = 0; i < M; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 2; ++k) {
                for (int l = 0; l < 2; ++l) {
                    dp[i+1][(j+l*2)%3][l] += dp[i][j][k];
                }
            }
        }
        if(dp[i+1][0][0] + dp[i+1][0][1] >= n){
            M = i+1;
            break;
        }else n -= dp[i+1][0][0] + dp[i+1][0][1];
    }
    int val = 0;
    string ans;
    for (int i = M; i >= 2; --i) {
        if(dp[i][val][0] >= n){
            ans += '3';
        }else {
            ans += '5';
            n -= dp[i][val][0];
            val = (val+1)%3;
        }
    }
    val %= 3;
    if(val == 1) ans += '5';
    else ans += '3';
    ans += '5';
    cout << ans << "\n";
    return 0;
}
0