結果

提出番号 1730
提出者 hamayanhamayan
言語 C++
提出日時 2018-08-04 13:40:02
問題名 (72)K-th DigitSum
結果 WA
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 WA 0% 4ms 7600KB
2 WA 0% 3ms 8432KB
3 WA 0% 2ms 8448KB
4 WA 0% 2ms 8688KB
5 WA 0% 4ms 8400KB
6 WA 0% 4ms 8000KB
7 WA 0% 4ms 8480KB
8 WA 0% 2ms 8720KB
9 WA 0% 4ms 8112KB
10 WA 0% 3ms 8736KB
11 WA 0% 2ms 8016KB
12 WA 0% 2ms 8144KB
13 WA 0% 2ms 8432KB
14 WA 0% 2ms 8672KB
15 WA 0% 4ms 7808KB
16 WA 0% 3ms 7808KB
17 WA 0% 4ms 7936KB
18 WA 0% 3ms 8272KB
19 WA 0% 2ms 8080KB
20 WA 0% 4ms 8416KB
21 WA 0% 3ms 8448KB
22 WA 0% 2ms 8192KB
23 WA 0% 3ms 8704KB
24 WA 0% 2ms 7824KB
25 WA 0% 2ms 8432KB
26 WA 0% 2ms 8064KB
27 WA 0% 3ms 8288KB
28 WA 0% 4ms 8416KB
29 WA 0% 2ms 7232KB
30 WA 0% 4ms 8144KB
31 WA 0% 5ms 8480KB
32 WA 0% 3ms 7776KB
33 WA 0% 3ms 8416KB
34 WA 0% 3ms 7872KB
35 WA 0% 2ms 8736KB
36 WA 0% 4ms 8432KB
37 WA 0% 4ms 8416KB
38 WA 0% 2ms 7920KB
39 WA 0% 4ms 8064KB
40 WA 0% 4ms 8720KB
41 WA 0% 2ms 8416KB
42 WA 0% 3ms 7632KB
43 WA 0% 2ms 8736KB
44 WA 0% 2ms 8720KB
45 WA 0% 4ms 7792KB
46 WA 0% 3ms 8416KB
47 WA 0% 2ms 8192KB
48 WA 0% 2ms 7792KB
49 WA 0% 3ms 8112KB
50 WA 0% 2ms 7632KB
51 WA 0% 2ms 8688KB

ソースコード

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




int N, K;
//---------------------------------------------------------------------------------------------------
#define CMAX 1010
int memo[CMAX][CMAX], vis[CMAX][CMAX];
int cmb(int d, int sm) {
    if (d < 0 or sm < 0) return 0;
    if (d == 0) {
        if (sm == 0) return 1;
        else return 0;
    }
    if (vis[d][sm]) return memo[d][sm];

    int res = 0;
    rep(i, 0, 10) res += cmb(d - 1, sm - i);
    vis[d][sm] = 1;
    return memo[d][sm] = res;
}
//---------------------------------------------------------------------------------------------------
void phase2(int d, int n) {
    printf("%d %d\n", d, n);

    printf("%d", n); N -= n;
    rrep(dd, d - 1, 2) rep(nn, 0, 10) {
        int cnt = cmb(dd - 1, N - nn);
        if (cnt <= K) K -= cnt;
        else {
            printf("%d", nn);
            N -= nn;
            break;
        }
    }
    if(1 < d) printf("%d\n", N);
    else printf("\n");
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;
    K--;

    rep(d, 1, 1010) rep(n, 1, 10) {
        int cnt = cmb(d - 1, N - n);
        if (cnt <= K) K -= cnt;
        else {
            phase2(d, n);
            return;
        }
    }
}