結果

問題 No.319 happy b1rthday 2 me
ユーザー rickythetarickytheta
提出日時 2015-12-12 00:46:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,789 bytes
コンパイル時間 1,154 ms
コンパイル使用メモリ 147,772 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-13 11:32:00
合計ジャッジ時間 2,296 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,352 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,356 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1 ms
4,352 KB
testcase_30 WA -
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

ll calc(string s){
  ll ret = 0;
  int n = s.size();
  // include '12'
  // keta/less/beforeIs1/cnt12
  ll dp[n+1][2][2][10]; fill(dp[0][0][0],dp[n+1][0][0],0ll);
  dp[0][0][0][0] = 1;
  REP(keta,n)REP(less,2)REP(bef,2)REP(cnt,10){
    int d = s[keta]-'0';
    REP(t,10){
      if(less || t<d || (t==d&&!less) )dp[keta+1][less || t<d][t==1][min(9ll,cnt+(ll)(bef&&t==2))]
        += dp[keta][less][bef][cnt];
    }
  }
  REP(bef,2)REP(less,2)REP(cnt,10) ret += cnt*dp[n][less][bef][cnt];
  //
  // conected '12'
  // keta/less/topis2/endis1
  fill(dp[0][0][0],dp[n+1][0][0],0ll);
  dp[0][0][0][0] = 1;
  REP(keta,n)REP(less,2)REP(top,2)REP(end,2){
    int d = s[keta]-'0';
    REP(t,10){
      if(less || t<d || (t==d&&!less))
        dp[keta+1][less||t<d][top||(keta==0&&t==2)][end||(keta==n-1&&t==1)]
          += dp[keta][less][top][end];
    }
  }
  REP(less,2) ret += dp[n][less][1][1];
  if(s[s.size()-1]=='1' && s[0]=='2')--ret;
  return ret;
}

int main(){
  string a,b;
  cin >> a >> b;
  string c = a;
  int iter = c.size()-1;
  while(c[iter]=='0'){
    c[iter] = '9';
    --iter;
  }
  --c[iter];
  ll result = 0;
  result += calc(b);
  result -= calc(c);
  if(c[c.size()-1]=='1' && a[0]=='2')result -= 1;
  cout << result << endl;
  return 0;
}
0