結果

問題 No.1953 8
ユーザー 沙耶花沙耶花
提出日時 2022-05-20 22:55:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,521 bytes
コンパイル時間 4,625 ms
コンパイル使用メモリ 263,692 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-20 13:45:53
合計ジャッジ時間 8,703 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,348 KB
testcase_01 AC 6 ms
4,368 KB
testcase_02 AC 14 ms
4,368 KB
testcase_03 AC 6 ms
4,368 KB
testcase_04 AC 5 ms
4,368 KB
testcase_05 AC 6 ms
4,368 KB
testcase_06 AC 5 ms
4,368 KB
testcase_07 AC 5 ms
4,368 KB
testcase_08 AC 6 ms
4,368 KB
testcase_09 AC 5 ms
4,368 KB
testcase_10 AC 5 ms
4,368 KB
testcase_11 AC 5 ms
4,368 KB
testcase_12 AC 6 ms
4,368 KB
testcase_13 AC 6 ms
4,368 KB
testcase_14 AC 7 ms
4,368 KB
testcase_15 AC 6 ms
4,368 KB
testcase_16 AC 7 ms
4,368 KB
testcase_17 AC 8 ms
4,368 KB
testcase_18 AC 9 ms
4,368 KB
testcase_19 AC 10 ms
4,368 KB
testcase_20 AC 11 ms
4,368 KB
testcase_21 AC 12 ms
4,368 KB
testcase_22 AC 12 ms
4,368 KB
testcase_23 AC 12 ms
4,368 KB
testcase_24 AC 13 ms
4,368 KB
testcase_25 AC 13 ms
4,368 KB
testcase_26 AC 14 ms
4,368 KB
testcase_27 AC 14 ms
4,368 KB
testcase_28 AC 7 ms
4,368 KB
testcase_29 AC 7 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001
int get(int n){
	if(n==8)return 2;
	if(n==0||n==6||n==9||n==4)return 1;
	return 0;
}

long long dp[18][2][2];
bool f[18][2][2];

long long dfs(string &s,string &t,int a,int b,int c){
	if(a==s.size()){
		return 1;
	}
	if(f[a][b][c])return dp[a][b][c];
	long long ret= 0;
	rep(i,10){
		if(t[a]!='*'){
			if(i!=t[a]-'0')continue;
			if(t[a]=='0'&&c==0)continue;
		}
		int aa = a+1;
		int bb = b;
		int cc = c;
		if(i!=0)cc = 1;
		if(b==0&&s[a]-'0' < i)continue;
		if(s[a]-'0' > i)bb = 1;
		ret += dfs(s,t,aa,bb,cc);
	}
	dp[a][b][c] = ret;
	f[a][b][c] = true;
	return ret;
}

long long get(string s,string t){
	//cout<<s<<','<<t<<endl;
	rep(i,18){
		rep(j,2){
			rep(k,2){
				dp[i][j][k] = 0;
				f[i][j][k] = false;
			}
		}
	}
	
	return dfs(s,t,0,0,0);
	
}

long long gg(long long n){
	string s = to_string(n);
	long long ret = 0;
	rep(i,10){
		int c = get(i);
		if(c!=0){
			rep(j,s.size()){
				string t(s.size(),'*');
				t[j] = '0'+i;
				ret += get(s,t) * c;
			}
		}
	}
	return ret;
}

int main() {
    
	long long K;
	cin>>K;
	long long ng=  0,ok = 100000000000000000;
	//cout<<gg(100000000000000000)<<endl;
	//return 0;
	while(ok-ng>1LL){
		long long mid = (ok+ng)/2;
		if(gg(mid)>=K)ok = mid;
		else ng = mid;
		
	}
	//cout<<ok<<','<<gg(ok)<<endl;
	if(gg(ok)==K)cout<<ok<<endl;
	else cout<<-1<<endl;
	
	
    return 0;
}
0