結果

問題 No.362 門松ナンバー
ユーザー h_nosonh_noson
提出日時 2016-05-24 21:31:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 3,000 ms
コード長 1,783 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 69,860 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 12:22:27
合計ジャッジ時間 2,028 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,248 KB
testcase_01 AC 6 ms
5,376 KB
testcase_02 AC 6 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 8 ms
5,376 KB
testcase_06 AC 14 ms
5,376 KB
testcase_07 AC 9 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 18 ms
5,376 KB
testcase_10 AC 24 ms
5,376 KB
testcase_11 AC 22 ms
5,376 KB
testcase_12 AC 22 ms
5,376 KB
testcase_13 AC 23 ms
5,376 KB
testcase_14 AC 23 ms
5,376 KB
testcase_15 AC 23 ms
5,376 KB
testcase_16 AC 22 ms
5,376 KB
testcase_17 AC 20 ms
5,376 KB
testcase_18 AC 23 ms
5,376 KB
testcase_19 AC 12 ms
5,376 KB
testcase_20 AC 23 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define debug cout << "debug" << endl; exit(1);
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
#define INF (int)1e8
#define MOD (int)1e9+7

typedef long long ll;


bool is_kadomatsu(int a, int b, int c) {
    return a != c && (b < min(a,c) || b > max(a,c));
}

ll count(ll x) {
    ll dp[2][13][10][10] {};
    int i, a, b, c;
    ll ret;
    vector<int> xs;
    while (x > 0) {
        xs.push_back(x%10);
        x /= 10;
    }
    reverse(xs.begin(),xs.end());
    rep (a,10) rep (b,10) {
        if (a == xs[0]) {
            if (b == xs[1])
                dp[0][0][a][b] = 1;
            else if (b < xs[1])
                dp[1][0][a][b] = 1;
        }
        else if (a < xs[0])
            dp[1][0][a][b] = 1;
    }
    vector<int> newxs(next(xs.begin(),2),xs.end());
    rep (i,newxs.size()) rep (a,10) rep (b,10) rep (c,10) {
        if (is_kadomatsu(a,b,c)) {
            if (c == newxs[i])
                dp[0][i+1][b][c] += dp[0][i][a][b];
            dp[1][i+1][b][c] += dp[1][i][a][b] + (c < newxs[i] ? dp[0][i][a][b] : 0);
        }
        else if (a == 0)
            dp[1][i+1][b][c]++;
    }
    ret = 0;
    rep (i,2) rep (a,10) rep (b,10) ret += dp[i][newxs.size()][a][b];
    return ret-100;
}

int main(void) {
    int t;
    cin >> t;
    while (t--) {
        ll k, l, r;
        cin >> k;
        l = 101; r = 1e14;
        while (l+1 < r) {
            ll m;
            m = (l+r)/2;
            if (count(m) < k)
                l = m;
            else
                r = m;
        }
        cout << r << endl;
    }
    return 0;
}
0