結果
問題 | No.362 門松ナンバー |
ユーザー |
![]() |
提出日時 | 2016-05-24 21:31:23 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 23 ms / 3,000 ms |
コード長 | 1,783 bytes |
コンパイル時間 | 731 ms |
コンパイル使用メモリ | 70,120 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-07 06:44:58 |
合計ジャッジ時間 | 2,015 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#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+7typedef 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;elser = m;}cout << r << endl;}return 0;}