結果
| 問題 |
No.362 門松ナンバー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-05 16:38:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 147 ms / 3,000 ms |
| コード長 | 1,078 bytes |
| コンパイル時間 | 712 ms |
| コンパイル使用メモリ | 75,264 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-14 01:19:34 |
| 合計ジャッジ時間 | 3,713 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
コンパイルメッセージ
main.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
46 | main()
| ^~~~
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long count(long L)
{
vector<int>S;
while(L)
{
S.push_back(L%10);
L/=10;
}
reverse(S.begin(),S.end());
long dp[20][2][11][11][11]={};
dp[0][0][10][10][10]=1;
for(int i=0;i<S.size();i++)for(int j=0;j<2;j++)
{
int lim=j?9:S[i];
for(int a=0;a<=10;a++)for(int b=0;b<=10;b++)for(int c=0;c<=10;c++)
{
if(dp[i][j][a][b][c]==0)continue;
for(int d=c==10;d<=lim;d++)
{
if(b<10)
{
if(b!=c&&c!=d&&d!=b&&(b<c&&d<c||b>c&&d>c))
{
dp[i+1][j||d<lim][b][c][d]+=dp[i][j][a][b][c];
}
}
else
{
dp[i+1][j||d<lim][b][c][d]+=dp[i][j][a][b][c];
}
}
if(c==10)dp[i+1][1][b][c][10]+=dp[i][j][a][b][c];
}
}
long ret=0;
for(int a=0;a<10;a++)for(int b=0;b<10;b++)for(int c=0;c<10;c++)
{
ret+=dp[S.size()][0][a][b][c]+dp[S.size()][1][a][b][c];
}
return ret;
}
main()
{
int T;cin>>T;
for(;T--;)
{
long K;
cin>>K;
long L=100,R=1e15;
while(R-L>1)
{
long M=(L+R)/2;
if(count(M)>=K)R=M;
else L=M;
}
cout<<R<<endl;
}
}