結果

問題 No.319 happy b1rthday 2 me
ユーザー koyumeishi
提出日時 2015-12-12 01:36:51
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,695 bytes
コンパイル時間 1,103 ms
コンパイル使用メモリ 84,928 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-15 08:33:57
合計ジャッジ時間 1,783 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
/*
1***2 1***3 1***4 ...
2***1 2***2
dp[sml][last] := cnt 12
dp[head][edge]
*/
//resize(vector, {v1,v2,v3});
void resize(int& val , vector<int>::iterator itr){val = 0;}
void resize(long long& val , vector<int>::iterator itr){val = 0;}
void resize(double& val , vector<int>::iterator itr){val = 0;}
template<class T>
void resize(vector<T>& vec, vector<int>::iterator itr){
vec.resize(*itr);
for(int i=0; i<*itr; i++){
resize(vec[i], itr+1);
}
}
template<class T>
void resize(T& vec, vector<int> sz){
resize(vec, sz.begin());
}
template<class T>
ostream& operator << (ostream& os, vector<T> vec){
for(int i=0; i<vec.size(); i++){
os << vec[i] << " ";
}
os << endl;
return os;
}
long long calc(string& x){
vector<vector<vector<long long>>> dp(2, vector<vector<long long>>(10,vector<long long>(11, 0)));
dp[0][0][0] = 1;
for(int i=0; i<x.size(); i++){
int k = x[i]-'0';
vector<vector<vector<long long>>> dp_(2, vector<vector<long long>>(10,vector<long long>(11, 0)));
for(int a=0; a<2; a++)
for(int b=0; b<10; b++)
for(int c=0; c<10; c++){
if(dp[a][b][c] == 0) continue;
for(int d=0; d<10; d++){
if(a==0 && k<d) break;
int a_ = a|(d<k);
int b_ = d;
int c_ = c + ((b*10+d==12)?1:0);
dp_[a_][b_][c_] += dp[a][b][c];
}
}
swap(dp, dp_);
}
long long ret = 0;
for(int a=0; a<2; a++)
for(int b=0; b<10; b++)
for(int c=1; c<11; c++){
ret += dp[a][b][c] * c;
}
return ret;
}
/*
10 11 12 13 14
*/
long long calc2(string &x){
vector<vector<long long>> dp(4, vector<long long>(2, 0));
long long ret = 0;
dp[0][1] = 1;
for(int i=0; i<x.size(); i++){
int k = x[i] - '0';
vector<vector<long long>> dp_(4, vector<long long>(2, 0));
for(int a=0; a<4; a++)
for(int b=0; b<2; b++){
if(dp[a][b]==0) continue;
for(int d=0; d<10; d++){
if(b==1 && d>k) break;
int a_ = (a>0?a:min(d,3));
int b_ = b & (d==k);
dp_[a_][b_] += dp[a][b];
if(i==x.size()-1){
//if(a_==1 && d==2 && b_==0){
// ret += dp[a][b];
//}
if(a_==2 && d==1 && b_==0){
ret += dp[a][b];
}
}
}
}
swap(dp, dp_);
}
return ret;
}
int main(){
long long a,b;
cin >> a >> b;
a--;
string a_,b_;
char buff[100];
sprintf(buff,"%lld", a);
a_ = buff;
sprintf(buff,"%lld", b);
b_ = buff;
long long ans = 0;
ans += calc(b_);
ans += calc2(b_);
ans -= calc(a_);
a++;
sprintf(buff,"%lld", a);
a_ = buff;
ans -= calc2(a_);
if(a<=1 && b>=2) ans++;
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0