結果
問題 |
No.319 happy b1rthday 2 me
|
ユーザー |
![]() |
提出日時 | 2015-12-12 01:04:33 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,566 bytes |
コンパイル時間 | 1,386 ms |
コンパイル使用メモリ | 163,300 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-15 08:31:47 |
合計ジャッジ時間 | 2,345 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 WA * 2 |
ソースコード
#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 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; } long long naive(long long a,long long b){ string s; for(int i = a ; i <= b ; i++){ stringstream ss; ss << i; s += ss.str(); } int ans = 0; for(int i = 0 ; i+1 < s.size() ; i++){ if( s[i] == '1' && s[i+1] == '2' ) ans++; } return ans; } int main(){ long long a,b; cin >> a >> b; //cout << naive(a,b) << endl; cout << doit(b) - doit(a-1)+isbad(b)-isbad(a) << endl; }