結果
問題 | No.319 happy b1rthday 2 me |
ユーザー |
![]() |
提出日時 | 2015-12-12 01:12:21 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,608 bytes |
コンパイル時間 | 1,449 ms |
コンパイル使用メモリ | 164,396 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 08:32:29 |
合計ジャッジ時間 | 2,376 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
#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;}}