結果

問題 No.294 SuperFizzBuzz
ユーザー t98slidert98slider
提出日時 2023-02-21 07:17:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,356 bytes
コンパイル時間 1,710 ms
コンパイル使用メモリ 167,196 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 02:25:10
合計ジャッジ時間 3,110 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 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 <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll th;
    cin >> th;
    string s(25, '9');
    auto f = [&](string s){
        int n = s.size();
        ll dp[n + 1][2][2][3] = {};
        dp[0][1][1][0] = 1;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 2; j++){
                int r = j & 1 ? s[i] - '0' : 9;
                for(int k = 0; k < 2; k++){
                    for(int l = 0; l < 3; l++){
                        if(i != n - 1){
                            if(k) dp[i + 1][(r == 0) & j][1][l] += dp[i][j][k][l];
                            if(3 <= r) dp[i + 1][(r == 3) & j][0][l] += dp[i][j][k][l];
                        }
                        if(5 <= r) dp[i + 1][(r == 5) & j][0][(l + 2) % 3] += dp[i][j][k][l];
                    }
                }
            }
        }
        return dp[n][1][0][0] + dp[n][0][0][0];
    };
    for(int i = 0; i < 25; i++){
        int ng = -1, ok = 9, mid;
        while(ng + 1 < ok){
            mid = (ng + ok) / 2;
            s[i] = mid + '0';
            if(th <= f(s)) ok = mid;
            else ng = mid;
        }
        s[i] = ok + '0';
    }
    reverse(s.begin(), s.end());
    while(s.back() == '0')s.pop_back();
    reverse(s.begin(), s.end());
    cout << s << '\n';
}
0