結果
問題 |
No.362 門松ナンバー
|
ユーザー |
![]() |
提出日時 | 2016-03-23 22:52:37 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 53 ms / 3,000 ms |
コード長 | 2,398 bytes |
コンパイル時間 | 957 ms |
コンパイル使用メモリ | 100,400 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-01 21:40:00 |
合計ジャッジ時間 | 2,627 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <cmath> #include <functional> #include <set> #include <ctime> #include <random> #include <chrono> using namespace std; template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;} template<class T> istream& operator , (istream& is, T& val){ return is >> val;} template<class T> ostream& operator << (ostream& os, const vector<T>& vec){for(int i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"":" "); return os;} template<class T> ostream& operator , (ostream& os, const T& val){ return os << " " << val;} template<class T> ostream& operator >> (ostream& os, const T& val){ return os << " " << val;} long long cnt_kado_num(long long x){ string s; char buff[100]; sprintf(buff,"%lld", x); s = buff; vector<vector<vector<long long>>> dp(11, vector<vector<long long>>(11, vector<long long>(2, 0))); dp[10][10][0] = 1; for(int i=0; i<s.size(); i++){ int k = s[i] - '0'; vector<vector<vector<long long>>> dp_(11, vector<vector<long long>>(11, vector<long long>(2, 0))); for(int c=1; c<10; c++){ if(i==0) dp_[10][c][c<k] += c<=k?1:0; else dp_[10][c][1] += 1; } for(int b=1; b<10; b++){ for(int c=0; c<10; c++){ if(b==c) continue; for(int t=0; t<2; t++){ if(t==0 && c>k) continue; int t_ = t || c<k; dp_[b][c][t_] += dp[10][b][t]; } } } for(int b=0; b<10; b++){ for(int t=0; t<2; t++){ for(int c=0; c<b; c++){ if(t==0 && c>k) break; for(int a=0; a<b; a++){ if(a==c) continue; int t_ = t || c<k; dp_[b][c][t_] += dp[a][b][t]; } } for(int c=b+1; c<10; c++){ if(t==0 && c>k) break; for(int a=b+1; a<10; a++){ if(a==c) continue; int t_ = t || c<k; dp_[b][c][t_] += dp[a][b][t]; } } } } swap(dp, dp_); } long long ret = 0; for(int a=0; a<10; a++) for(int b=0; b<10; b++) for(int t=0; t<2; t++){ ret += dp[a][b][t]; } return ret; } int main(){ int t; cin >> t; long long d = cnt_kado_num(99); while(t--){ long long k; cin >> k; k += d; long long lb = 0; long long ub = 1LL<<58; while(ub-lb>1){ long long mid = (lb+ub)/2; (cnt_kado_num(mid)>=k ? ub : lb) = mid; } cout << ub << endl; } return 0; }