結果
| 問題 |
No.319 happy b1rthday 2 me
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-12-20 01:33:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,752 bytes |
| コンパイル時間 | 748 ms |
| コンパイル使用メモリ | 92,352 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-17 11:13:35 |
| 合計ジャッジ時間 | 1,555 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
ソースコード
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;
long long solve(long long n)
{
if(n < 2)
return 0;
long long mod = 1000000000000;
vector<long long> dp(4, 0);
dp[0] = 1;
long long ans = 1;
while(mod > 0){
if(n / mod > 2)
ans += mod / 10;
else if(n / mod == 2)
ans += (n % mod + 8) / 10;
int curr = n / mod % 10;
vector<long long> nextDp(4, 0);
for(int i=0; i<4; ++i){
if(dp[i] == 0)
continue;
for(int a=0; a<=9; ++a){
if(!(i & 1) && curr < a)
continue;
if((i & 2) && a == 2){
if((i & 1) || a < curr)
ans += dp[i] * mod;
else
ans += (dp[i] - 1) * mod + n % mod + 1;
}
int k = i & 1;
if(a < curr)
k |= 1;
if(a == 1)
k |= 2;
nextDp[k] += dp[i];
}
}
dp.swap(nextDp);
mod /= 10;
}
return ans;
}
int main()
{
long long a, b;
cin >> a >> b;
long long ans = solve(b) - solve(a-1);
if((a - 1) % 10 == 1){
long long x = a;
while(x >= 10)
x /= 10;
if(x == 2)
-- ans;
}
cout << ans << endl;
return 0;
}