結果

問題 No.362 門松ナンバー
ユーザー koyumeishikoyumeishi
提出日時 2016-03-23 22:52:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 54 ms / 3,000 ms
コード長 2,398 bytes
コンパイル時間 997 ms
コンパイル使用メモリ 102,056 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 21:13:03
合計ジャッジ時間 2,480 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
6,812 KB
testcase_01 AC 15 ms
6,940 KB
testcase_02 AC 15 ms
6,940 KB
testcase_03 AC 8 ms
6,940 KB
testcase_04 AC 5 ms
6,944 KB
testcase_05 AC 23 ms
6,940 KB
testcase_06 AC 40 ms
6,944 KB
testcase_07 AC 21 ms
6,940 KB
testcase_08 AC 28 ms
6,944 KB
testcase_09 AC 45 ms
6,940 KB
testcase_10 AC 52 ms
6,940 KB
testcase_11 AC 51 ms
6,944 KB
testcase_12 AC 52 ms
6,940 KB
testcase_13 AC 52 ms
6,944 KB
testcase_14 AC 52 ms
6,940 KB
testcase_15 AC 52 ms
6,940 KB
testcase_16 AC 52 ms
6,944 KB
testcase_17 AC 49 ms
6,944 KB
testcase_18 AC 54 ms
6,940 KB
testcase_19 AC 36 ms
6,940 KB
testcase_20 AC 53 ms
6,948 KB
testcase_21 AC 6 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0