結果
問題 | No.319 happy b1rthday 2 me |
ユーザー | kyuridenamida |
提出日時 | 2015-12-12 00:55:06 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,468 bytes |
コンパイル時間 | 1,471 ms |
コンパイル使用メモリ | 163,952 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-15 08:31:13 |
合計ジャッジ時間 | 2,328 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 15 WA * 14 |
ソースコード
#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 doit(long long a){ long long fix = 0; stringstream ss; ss << a; s = ss.str(); if( s[0] == '2' && s[s.size()-1] != '1' ){ fix++; cout << a << endl; } 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 << doit(b) - doit(a-1) << endl; }