結果
| 問題 |
No.319 happy b1rthday 2 me
|
| コンテスト | |
| ユーザー |
piyoko_212
|
| 提出日時 | 2015-12-21 19:08:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 1,351 bytes |
| コンパイル時間 | 277 ms |
| コンパイル使用メモリ | 36,944 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-18 18:03:57 |
| 合計ジャッジ時間 | 1,318 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:55:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
55 | scanf("%lld%lld",&A,&B);
| ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
char str[20];
long long dp[20][10][10][2][3];
long long f(long long n){
if(n==0)return 0LL;
sprintf(str,"%lld",n);
int len=strlen(str);
for(int i=0;i<20;i++)for(int j=0;j<10;j++)for(int k=0;k<10;k++)for(int l=0;l<2;l++)for(int m=0;m<3;m++)
dp[i][j][k][l][m]=0;
for(int i=1;i<10;i++){
int tmp=0;
if(i<str[0]-'0')tmp=1;
if(i>str[0]-'0')tmp=2;
dp[1][0][i][i==2][tmp]=1;
}
for(int i=1;i<len;i++){
for(int j=0;j<10;j++){
for(int k=0;k<10;k++){
for(int l=0;l<2;l++)for(int m=0;m<3;m++){
if(!dp[i][j][k][l][m])continue;
for(int r=0;r<10;r++){
int tj=j;
int tm=m;
if(k==1&&r==2)tj++;
if(m==0&&r<str[i]-'0')tm=1;
if(m==0&&r>str[i]-'0')tm=2;
dp[i+1][tj][r][l][tm]+=dp[i][j][k][l][m];
}
}
}
}
}
long long ret=0;
if(n>=2)ret++;
for(int i=1;i<=len;i++){
for(int j=0;j<10;j++){
for(int k=0;k<10;k++){
for(int l=0;l<2;l++)for(int m=0;m<3;m++){
if(i==len&&m==2)continue;
ret+=dp[i][j][k][l][m]*j;
if((m||i!=len)&&l&&k==1){
ret+=dp[i][j][k][l][m];
}
}
}
}
}
return ret;
}
int main(){
long long A,B;
scanf("%lld%lld",&A,&B);
long long ret=f(B)-f(A-1);
if((A-1)%10==1){
long long c=A;
while(c>=10)c/=10;
if(c==2)ret--;
}
printf("%lld\n",ret);
}
piyoko_212