結果

問題 No.362 門松ナンバー
ユーザー rickythetarickytheta
提出日時 2016-04-18 12:11:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 81 ms / 3,000 ms
コード長 1,589 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 160,016 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 03:27:27
合計ジャッジ時間 3,258 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
6,812 KB
testcase_01 AC 21 ms
6,944 KB
testcase_02 AC 21 ms
6,940 KB
testcase_03 AC 11 ms
6,944 KB
testcase_04 AC 7 ms
6,944 KB
testcase_05 AC 32 ms
6,940 KB
testcase_06 AC 57 ms
6,940 KB
testcase_07 AC 31 ms
6,944 KB
testcase_08 AC 40 ms
6,944 KB
testcase_09 AC 63 ms
6,940 KB
testcase_10 AC 78 ms
6,940 KB
testcase_11 AC 76 ms
6,940 KB
testcase_12 AC 76 ms
6,940 KB
testcase_13 AC 78 ms
6,940 KB
testcase_14 AC 78 ms
6,944 KB
testcase_15 AC 77 ms
6,940 KB
testcase_16 AC 75 ms
6,940 KB
testcase_17 AC 67 ms
6,940 KB
testcase_18 AC 81 ms
6,944 KB
testcase_19 AC 49 ms
6,940 KB
testcase_20 AC 81 ms
6,944 KB
testcase_21 AC 9 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:54:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |   scanf("%lld",&k);
      |   ~~~~~^~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:68:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |   scanf("%d",&t);
      |   ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

// keta less bef2 bef1
ll dp[20][2][11][11];

ll count(ll bound){
  // keta dp
  string s = to_string(bound);
  int n = s.size();
  REP(i,n+1)REP(j,2)REP(k,11)REP(l,11)dp[i][j][k][l] = 0;
  dp[0][0][10][10] = 1;
  REP(keta,n){
    int d = s[keta]-'0';
    REP(less,2)REP(bef2,11)REP(bef1,11){
      REP(k,10){
        if(less || k<=d){
          int nl = less || k<d;
          if(bef1==10 || (bef2==10&&bef1!=k) || (bef2<bef1 && bef1>k && bef2!=k) || (bef2>bef1 && bef1<k && bef2!=k)){
            // ok
            dp[keta+1][nl][bef1][(bef1==10&&k==0)?10:k] += dp[keta][less][bef2][bef1];
          }
        }
      }
    }
  }
  ll ans = 0;
  REP(less,2)REP(bef2,10)REP(bef1,10){
    ans += dp[n][less][bef2][bef1];
  }
  return ans;
}

void solve(){
  ll k;
  scanf("%lld",&k);
  k += count(100);
  ll low = 0, high = 1e17;
  while(low+1<high){
    ll mid = (low+high)/2;
    ll cnt = count(mid);
    if(cnt>=k) high = mid;
    else low = mid;
  }
  printf("%lld\n",high);
}

int main(){
  int t;
  scanf("%d",&t);
  while(t--)solve();
  return 0;
}
0