結果
問題 | No.362 門松ナンバー |
ユーザー |
|
提出日時 | 2016-04-18 00:01:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 3,000 ms |
コード長 | 2,182 bytes |
コンパイル時間 | 1,126 ms |
コンパイル使用メモリ | 112,564 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-10 23:58:52 |
合計ジャッジ時間 | 1,999 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#define _USE_MATH_DEFINES#include <cstdio>#include <iostream>#include <sstream>#include <fstream>#include <iomanip>#include <algorithm>#include <cmath>#include <complex>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <set>#include <map>#include <bitset>#include <numeric>#include <limits>#include <climits>#include <cfloat>#include <functional>using namespace std;bool checkKadomatsu(const vector<int>& a){if(a[0] == a[2])return false;return (a[0] < a[1] && a[2] < a[1]) || (a[0] > a[1] && a[2] > a[1]);}long long solve(long long k){vector<vector<vector<long long> > > dp(1, vector<vector<long long> >(10, vector<long long>(10, 1)));for(int i=1; ; ++i){dp.push_back(vector<vector<long long> >(10, vector<long long>(10, 0)));for(int b=0; b<=9; ++b){for(int a=0; a<=9; ++a){for(int c=0; c<=9; ++c){if(checkKadomatsu({c, b, a})){dp[i][c][b] += dp[i-1][b][a];}}}}int a, b;for(b=1; b<=9; ++b){for(a=0; a<=9; ++a){if(k > dp[i][b][a])k -= dp[i][b][a];elsebreak;}if(a < 10)break;}if(b < 10){long long ans = b * 10 + a;for(int j=i-1; j>=0; --j){for(int c=0; ; ++c){if(checkKadomatsu({b, a, c})){if(k > dp[j][a][c]){k -= dp[j][a][c];}else{ans *= 10;ans += c;b = a;a = c;break;}}}}return ans;}}}int main(){int t;cin >> t;while(--t >= 0){long long k;cin >> k;cout << solve(k) << endl;}return 0;}