結果

問題 No.319 happy b1rthday 2 me
ユーザー しらっ亭しらっ亭
提出日時 2016-05-16 16:36:17
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,185 bytes
コンパイル時間 1,447 ms
コンパイル使用メモリ 161,260 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 22:27:25
合計ジャッジ時間 2,609 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FORR(x,arr) for(auto&& x:arr)
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
typedef long long ll;
// -------------------------------------

ll dp1[13][2][2][10];  // pos, less, last1, num12

ll count1(string& S) {
  int N = SZ(S);

  memset(dp1, 0, sizeof(dp1));
  dp1[0][0][0][0] = 1;

  REP(i, N) REP(j, 2) REP(k, 2) REP(l, 10) {
    int lim = j ? 9 : S[i] - '0';
    REP(d, lim + 1) {
      if (k && d == 2) {
        dp1[i+1][j || d < lim][0][l+1] += dp1[i][j][k][l];
      }
      else {
        dp1[i+1][j || d < lim][d==1][l] += dp1[i][j][k][l];
      }
    }
  }

  ll ans = 0;
  REP(j, 2) REP(k, 2) REP(l, 10) {
    ans += dp1[N][j][k][l] * l;
  }
  return ans;
}

ll dp2[13][2][2][2][2];  // pos, less, lead0, first2, last2

ll count2(string& S) {
  int N = SZ(S);

  memset(dp2, 0, sizeof(dp2));
  dp2[0][0][1][0][0] = 1;

  REP(i, N) REP(j, 2) REP(k, 2) REP(l, 2) REP(m, 2) {
    int lim = j ? 9 : S[i] - '0';
    REP(d, lim + 1) {
      dp2[i+1][j || d < lim][k && d == 0][l || (k && d == 2)][i==N-1 && d == 2] += dp2[i][j][k][l][m];
    }
  }

  ll ans = 0;
  REP(j, 2) {
    ans += dp2[N][j][0][1][1];
  }
  return ans;
}

string dec(string S) {
  int bollow = 1;
  for (int i = S.length() - 1; i >= 0; i--) {
    int p = S[i] - '0';
    if (p - bollow < 0) {
      S[i] = '9';
      bollow = 1;
    }
    else {
      S[i] = (p - bollow) + '0';
      break;
    }
  }
  return S;
}

void Main() {
  string A, B;
  cin >> A >> B;

  string da(dec(A));

  ll a1 = count1(da);
  ll b1 = count1(B);
  ll a2 = count2(da);
  ll b2 = count2(B);

  //_P("%lld + %lld = %lld\n", a1, a2, a1+a2);
  //_P("%lld + %lld = %lld\n", b1, b2, b1+b2);
  ll ans = b1 + b2 - a1 - a2;
  if (A[0] == '2' && A.back() == '2') ans--;

  cout << ans << endl;
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }
0