| 提出番号 | 1866 |
|---|---|
| 提出者 | popo |
| 言語 | C++ |
| 提出日時 | 2018-08-04 14:16:33 |
| 問題名 | (72)K-th DigitSum |
| 結果 | MLE |
| 点数 | 0% |
| テストケース | 結果 | 得点 | 実行時間 | メモリ使用量 |
|---|---|---|---|---|
| 1 | MLE | 0% | 1125ms | 1007340KB |
| 2 | MLE | 0% | 1232ms | 1007340KB |
| 3 | MLE | 0% | 967ms | 1007340KB |
| 4 | MLE | 0% | 1109ms | 1007340KB |
| 5 | MLE | 0% | 1090ms | 1007340KB |
| 6 | MLE | 0% | 955ms | 1007330KB |
| 7 | MLE | 0% | 1023ms | 1007340KB |
| 8 | MLE | 0% | 988ms | 1007330KB |
| 9 | MLE | 0% | 953ms | 1007330KB |
| 10 | MLE | 0% | 951ms | 1007330KB |
| 11 | MLE | 0% | 1115ms | 1007340KB |
| 12 | MLE | 0% | 988ms | 1007340KB |
| 13 | MLE | 0% | 1216ms | 1007330KB |
| 14 | MLE | 0% | 1219ms | 1007330KB |
| 15 | MLE | 0% | 1030ms | 1007340KB |
| 16 | MLE | 0% | 998ms | 1007330KB |
| 17 | MLE | 0% | 1022ms | 1007340KB |
| 18 | MLE | 0% | 1046ms | 1007330KB |
| 19 | MLE | 0% | 958ms | 1007340KB |
| 20 | MLE | 0% | 987ms | 1007340KB |
| 21 | MLE | 0% | 962ms | 1007330KB |
| 22 | MLE | 0% | 987ms | 1007330KB |
| 23 | MLE | 0% | 950ms | 1007340KB |
| 24 | MLE | 0% | 986ms | 1007330KB |
| 25 | MLE | 0% | 954ms | 1007340KB |
| 26 | MLE | 0% | 972ms | 1007330KB |
| 27 | MLE | 0% | 1001ms | 1007340KB |
| 28 | MLE | 0% | 1114ms | 1007340KB |
| 29 | MLE | 0% | 1190ms | 1007330KB |
| 30 | MLE | 0% | 976ms | 1007340KB |
| 31 | MLE | 0% | 985ms | 1007330KB |
| 32 | MLE | 0% | 1229ms | 1007330KB |
| 33 | MLE | 0% | 969ms | 1007330KB |
| 34 | MLE | 0% | 1093ms | 1007340KB |
| 35 | MLE | 0% | 1096ms | 1007330KB |
| 36 | MLE | 0% | 1035ms | 1007330KB |
| 37 | MLE | 0% | 958ms | 1007330KB |
| 38 | MLE | 0% | 963ms | 1007330KB |
| 39 | MLE | 0% | 1095ms | 1007330KB |
| 40 | MLE | 0% | 966ms | 1007340KB |
| 41 | MLE | 0% | 990ms | 1007330KB |
| 42 | MLE | 0% | 983ms | 1007340KB |
| 43 | MLE | 0% | 1225ms | 1007330KB |
| 44 | MLE | 0% | 1111ms | 1007340KB |
| 45 | MLE | 0% | 957ms | 1007340KB |
| 46 | MLE | 0% | 997ms | 1007340KB |
| 47 | MLE | 0% | 1038ms | 1007330KB |
| 48 | MLE | 0% | 1101ms | 1007330KB |
| 49 | MLE | 0% | 975ms | 1007340KB |
| 50 | MLE | 0% | 1024ms | 1007340KB |
| 51 | MLE | 0% | 134ms | 1007380KB |
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
struct X{
int id,su,di;
X(){di=-1;}
X(int a,int c,int d){
id=a;
su=c;
di=d;
}
};
int dp[1009][1009][9],n,k;
X pre[1009][1009][9],p[1009][1009][9];
int prin(int a,int c,int d){
string ans="";
int a1=a,d1=d,c1=c;
while(a!=1001){
ans+=('0'+d);
int A=pre[a][c][d].id;
int C=pre[a][c][d].su;
int D=pre[a][c][d].di;
a=A;
c=C;
d=D;
}
while(1){
ans+=('0'+d1);
int A=p[a1][c1][d1].id;
int C=p[a1][c1][d1].su;
int D=p[a1][c1][d1].di;
a1=A;
c1=C;
d1=D;
if(d1==-1)break;
}
reverse(ans.begin(),ans.end());
int idx=0;
while(ans[idx]=='0')idx++;
for(;idx<ans.size();idx++)cout<<ans[idx];
cout<<endl;
exit(0);
}
int dfs(int idx,int sum=0,int dig=0){
if(idx==1001)return sum==n;
int &res=dp[idx][sum][dig];
if(~res)return res;
res=0;
for(int i=0;i<=9;i++){
p[idx+1][sum+i][i]=X(idx,sum,dig);
res+=dfs(idx+1,sum+i,i);
pre[idx][sum][dig]=X(idx+1,sum+i,i);
if(res==k){
prin(idx,sum,dig);
}
}
return res;
}
int main(){
memset(dp,-1,sizeof(dp));
cin>>n>>k;
dfs(0);
}