結果

問題 No.319 happy b1rthday 2 me
ユーザー hirokazu1020hirokazu1020
提出日時 2015-12-12 01:49:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,691 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 97,344 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 11:35:47
合計ジャッジ時間 2,004 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())



pair<long long, long long> dp[20][2][2];


long long f(string s) {
	if (s.size() < 2)return s[0]>='2';
	memset(dp,0,sizeof(dp));
	dp[0][0][0] = make_pair(1,0);
	rep(i,s.size())rep(j,2)rep(k,2) {
		pair<long long, long long> &a = dp[i][j][k];
		for (int d = 0; (d + '0' <= s[i] || j)&&d<10; d++) {
			pair<long long, long long> &b = dp[i+1][j||d+'0'<s[i]][d==1];
			b.first += a.first;
			b.second += a.second;
			if (k&&d == 2)b.second += a.first;
		}
	}
	long long res = 1;
	rep(j, 2)rep(k, 2)res += dp[s.size()][j][k].second;
	for (int i = 2; i < s.size(); i++) {
		long long p = 1;
		rep(j, i - 2)p *= 10;
		res += p;
	}
	if (s[0] == '2') {
		long long p = 0;
		for (int j = 1; j + 1 < s.size(); j++) {
			p *= 10;
			p += s[j] - '0';
		}
		res += p + 1;
		if (s[s.size() - 1] < '2')res--;
	}
	else if (s[0]>'2') {
		long long p = 1;
		rep(j, s.size() - 2)p *= 10;
		res += p;
	}

	return res;
}

int main() {
	string a,b;
	cin >> a>>b;
	int x = 0;
	rep(i, a.size() - 1)if (a[i] == '1'&&a[i + 1] == '2')x++;
	if (a == b) {
		cout << x << endl;
	}else {
		cout << f(b) - f(a) + x << endl;
	}
	return 0;
}
0