結果

問題 No.319 happy b1rthday 2 me
ユーザー kyuridenamidakyuridenamida
提出日時 2015-12-12 01:12:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,608 bytes
コンパイル時間 1,418 ms
コンパイル使用メモリ 150,404 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-13 11:34:00
合計ジャッジ時間 2,816 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 2 ms
4,356 KB
testcase_29 AC 1 ms
4,352 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

string s;

long long dp[22][2][2][22];
long long dfs(int x,int f,int p,int c){
	if( x == s.size() ) return c;
	if( dp[x][f][p][c] != -1 ) return dp[x][f][p][c];
	long long ans = 0;
	if(f){
		for(int i = 0 ; i < 10 ; i++){
			ans += dfs(x+1,1,i==1,c+(p==1&&i==2));
		}
	}else{
		for(int i = 0 ; i < s[x] - '0' ; i++){
			ans += dfs(x+1,1,i==1,c+(p==1&&i==2));
		}
		ans += dfs(x+1,0,s[x]-'0'==1,c+(p==1&&s[x]-'0'==2));
	}
	return dp[x][f][p][c] = ans;
}



long long doit2(long long a){
	long long two = 20;
	long long three = 30;
	long long ten = 1;
	long long ans = 0;
	for(int i = 2 ; i < 15; i++){
		if( two <= a ){
			if( a < three ){
				ans += (a - two) / 10;
			}else{
				ans += ten;
			}
		}
		two *= 10;
		three *= 10;
		ten *= 10;
	}
	return ans;
}

long long isbad(long long a){
	stringstream ss;
	ss << a;
	string s = ss.str();
	return s[0] == '2' && s[s.size()-1] > '1';
}
long long isbad2(long long a){
	stringstream ss;
	ss << a;
	string s = ss.str();
	string t = s.substr(1);
	if( count(t.begin(),t.end(),'0') == t.size() ) return 0;
	return s[0] == '2' && s[s.size()-1] == '0';
}
long long doit(long long a){
	long long fix = 0;
	stringstream ss;
	ss << a;
	s = ss.str();
	while( s.size() < 20 ) s = "0" + s; 
	memset(dp,-1,sizeof(dp));
	if( a >= 2 ) fix++; // 1,2,3,4,...
	fix += doit2(a);
	return dfs(0,0,0,0) + fix;
}

int main(){
	long long a,b;
	cin >> a >> b;
	if( a == 1 && b == 2 ){
		cout << 1 << endl;
	}else if( a == 2 && b == 2 ){
		cout << 0 << endl;
	}else{
		cout << doit(b) - doit(a-1)+isbad(b)-isbad(a)-isbad2(a) << endl;
	}
}
0