結果
問題 | No.319 happy b1rthday 2 me |
ユーザー |
|
提出日時 | 2020-02-22 17:21:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 981 bytes |
コンパイル時間 | 750 ms |
コンパイル使用メモリ | 74,788 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-09 17:37:50 |
合計ジャッジ時間 | 1,958 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
コンパイルメッセージ
main.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 45 | main() | ^~~~
ソースコード
#include<iostream>#include<vector>#include<algorithm>using namespace std;long f(long N){vector<int>d;long t=N;while(t){d.push_back(t%10);t/=10;}reverse(d.begin(),d.end());long dp[20][11][2][10][10]={};dp[0][0][0][0][0]=1;long ans=0;for(int i=0;i<d.size();i++)for(int I=0;I<10;I++)for(int j=0;j<2;j++){int lim=j?9:d[i];for(int k=0;k<10;k++)for(int l=0;l<10;l++){for(int x=0;x<=lim;x++){int nI=I;if(l==1&&x==2)nI++;dp[i+1][nI][j||x<lim][k?k:x][x]+=dp[i][I][j][k][l];}}}for(int i=0;i<11;i++){for(int k=0;k<10;k++)for(int l=0;l<10;l++)ans+=i*dp[d.size()][i][0][k][l]+i*dp[d.size()][i][1][k][l];ans+=dp[d.size()][i][0][2][1]+dp[d.size()][i][1][2][1];}if(N%10==1){long t=N;while(t>=10)t/=10;if(t==2)ans--;}if(N>=2)ans++;return ans;}main(){long A,B;cin>>A>>B;long ans=f(B)-f(A-1);if((A-1)%10==1){long t=A;while(t>=10)t/=10;if(t==2)ans--;}cout<<ans<<endl;}