結果

問題 No.319 happy b1rthday 2 me
ユーザー kotatsugamekotatsugame
提出日時 2020-02-22 06:09:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 987 bytes
コンパイル時間 887 ms
コンパイル使用メモリ 75,084 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 22:04:43
合計ジャッジ時間 1,978 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 3 ms
6,944 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 3 ms
6,940 KB
testcase_28 AC 3 ms
6,940 KB
testcase_29 AC 3 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 3 ms
6,944 KB
testcase_32 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   44 | main()
      | ^~~~

ソースコード

diff #

#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--;
	}
	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--;
	}
	if(A==1&&2<=B)ans++;
	cout<<ans<<endl;
}
0