結果

問題 No.362 門松ナンバー
ユーザー ei1333333ei1333333
提出日時 2016-04-17 23:25:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 80 ms / 3,000 ms
コード長 1,304 bytes
コンパイル時間 1,337 ms
コンパイル使用メモリ 162,312 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 02:29:09
合計ジャッジ時間 3,118 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
6,812 KB
testcase_01 AC 27 ms
6,944 KB
testcase_02 AC 27 ms
6,944 KB
testcase_03 AC 15 ms
6,940 KB
testcase_04 AC 9 ms
6,940 KB
testcase_05 AC 39 ms
6,940 KB
testcase_06 AC 70 ms
6,940 KB
testcase_07 AC 37 ms
6,940 KB
testcase_08 AC 44 ms
6,944 KB
testcase_09 AC 67 ms
6,944 KB
testcase_10 AC 77 ms
6,940 KB
testcase_11 AC 77 ms
6,944 KB
testcase_12 AC 77 ms
6,940 KB
testcase_13 AC 78 ms
6,940 KB
testcase_14 AC 76 ms
6,944 KB
testcase_15 AC 77 ms
6,944 KB
testcase_16 AC 77 ms
6,944 KB
testcase_17 AC 73 ms
6,944 KB
testcase_18 AC 80 ms
6,940 KB
testcase_19 AC 62 ms
6,944 KB
testcase_20 AC 80 ms
6,944 KB
testcase_21 AC 10 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int64;

int64 dp[2][3][11][10][500];  
string s;  
 
int64 rec(int idx, bool free, int pree, int pre, int pre_up)
{
  if(idx == s.size()) return(1);  
  if(~dp[free][pre_up][pree][pre][idx]) return dp[free][pre_up][pree][pre][idx];
  int64 ret = 0, end = free ? 9 : s[idx] - '0';  
  for(int i = 0; i <= end; i++) {
#define next(l) rec(idx + 1, free|(i != end), pre, i, l)  
    if(pre_up == 1 && pre <= i) continue;  
    if(pre_up == 2 && pre >= i) continue;
    if(pre_up == 0){
      if(pre && pre == i) continue;
      if(pre == 0) ret += next(0);  
      else if(pre < i) ret += next(1);  
      else if(pre > i) ret += next(2);  
    } else if(pre_up == 1) {
      if(pree == i) continue;
      ret += next(2);
    } else {
      if(pree == i) continue;
      ret += next(1);
    }
  }  
  return dp[free][pre_up][pree][pre][idx] = ret;
}  

int main()
{
  int T;
  cin >> T;

  while(T--) {
    int64 K;
    cin >> K;
    int64 low = 0, high = 37294859064823;
    while(high - low > 0) {
      int64 mid = (high + low) >> 1LL;
      stringstream sss; sss << mid;
      s = sss.str();
      memset(dp, -1, sizeof(dp));
      if(rec(0, 0, 0, 0, 0) - 91  < K) low = mid + 1;
      else high = mid;
    }
    cout << low << endl;
  }
}
0