結果

問題 No.319 happy b1rthday 2 me
ユーザー piyoko_212piyoko_212
提出日時 2015-12-21 19:02:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,335 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 37,020 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 22:02:08
合計ジャッジ時間 1,405 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 0 ms
4,348 KB
testcase_03 AC 0 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 0 ms
4,348 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 0 ms
4,348 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 0 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:54:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |         scanf("%lld%lld",&A,&B);
      |         ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#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;
	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);
}
0