結果

問題 No.260 世界のなんとか3
ユーザー shobonvipshobonvip
提出日時 2022-08-07 19:46:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,807 bytes
コンパイル時間 4,937 ms
コンパイル使用メモリ 264,808 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 14:28:51
合計ジャッジ時間 6,121 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 19 ms
4,348 KB
testcase_04 AC 19 ms
4,348 KB
testcase_05 AC 5 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 14 ms
4,348 KB
testcase_08 AC 10 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 16 ms
4,348 KB
testcase_11 AC 15 ms
4,348 KB
testcase_12 AC 10 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 14 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 12 ms
4,348 KB
testcase_17 AC 10 ms
4,348 KB
testcase_18 AC 10 ms
4,348 KB
testcase_19 AC 13 ms
4,348 KB
testcase_20 AC 9 ms
4,348 KB
testcase_21 AC 8 ms
4,348 KB
testcase_22 AC 13 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 11 ms
4,348 KB
testcase_25 AC 11 ms
4,348 KB
testcase_26 AC 10 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 20 ms
4,348 KB
testcase_29 AC 20 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)

typedef modint1000000007 mint;
typedef long long ll;

mint solve(string x, bool mode){
  int size = x.size();
  vector<mint> dpy(24);
  vector<mint> dpn(24);
  bool nowisy = false;
  int now24 = 0;
  for (int num=0; num<size; num++){
    vector<mint> ndpy(24);
    vector<mint> ndpn(24);
    
    //継続
    for (int i=0; i<10; i++){
      if (i==3){
        for (int j=0; j<24; j++){
          ndpy[(i+10*j)%24] += dpy[j] + dpn[j];
        }
      }else{
        for (int j=0; j<24; j++){
          ndpy[(i+10*j)%24] += dpy[j];
          ndpn[(i+10*j)%24] += dpn[j];
        }
      }
    }

    //新規
    if (num > 0){
      for (int i=1; i<10; i++){
        if (i==3) ndpy[i] += 1;
        else ndpn[i] += 1;
      }
    }

    int targ = x[num] - '0';

    //解放
    if (nowisy){
      for (int i=(num<1); i<targ; i++){
        ndpy[(i+10*now24)%24] += 1;
      }
    }else{
      for (int i=(num<1); i<targ; i++){
        if (i==3) ndpy[(i+10*now24)%24] += 1;
        else ndpn[(i+10*now24)%24] += 1;
      }
    }

    for (int i=0; i<24; i++){
      dpn[i] = ndpn[i];
      dpy[i] = ndpy[i];
    }

    if (targ == 3) nowisy = true;
    
    now24 = (10*now24+targ) % 24;
  }

  if (mode){
    if (nowisy) dpy[now24] += 1;
    else dpn[now24] += 1;
  }

  mint ans = 0;
  for (int i=0; i<24; i++){
    if (i%8 != 0){
      ans += dpy[i];
      if (i%3 == 0) ans += dpn[i];
    }
  }

  return ans;
}

int main(){
  string a, b;
  cin >> a >> b;
  mint ans = solve(b,true) - solve(a,false);
  cout << ans.val() << endl;
}
0