結果

問題 No.315 世界のなんとか3.5
ユーザー kurome____kurome____
提出日時 2016-03-02 10:54:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 1,682 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 163,320 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 19:31:30
合計ジャッジ時間 5,303 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 49 ms
4,372 KB
testcase_13 AC 50 ms
4,372 KB
testcase_14 AC 95 ms
4,372 KB
testcase_15 AC 94 ms
4,372 KB
testcase_16 AC 97 ms
4,372 KB
testcase_17 AC 99 ms
4,372 KB
testcase_18 AC 51 ms
4,372 KB
testcase_19 AC 51 ms
4,372 KB
testcase_20 AC 51 ms
4,372 KB
testcase_21 AC 51 ms
4,372 KB
testcase_22 AC 99 ms
4,372 KB
testcase_23 AC 98 ms
4,372 KB
testcase_24 AC 98 ms
4,372 KB
testcase_25 AC 100 ms
4,372 KB
testcase_26 AC 96 ms
4,372 KB
testcase_27 AC 97 ms
4,372 KB
testcase_28 AC 95 ms
4,372 KB
testcase_29 AC 171 ms
4,372 KB
testcase_30 AC 164 ms
4,372 KB
testcase_31 AC 166 ms
4,372 KB
testcase_32 AC 195 ms
4,372 KB
testcase_33 AC 99 ms
4,372 KB
testcase_34 AC 148 ms
4,372 KB
testcase_35 AC 243 ms
4,372 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘ll calc(std::string, int, int)’:
main.cpp:35:12: warning: ‘nxt’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |   int crt, nxt;
      |            ^~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define RFOR(i,e,s) for(int (i)=(e)-1;(i)>=(int)(s);(i)--)
#define RREP(i,e) RFOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;
typedef priority_queue<int> PQI;
typedef priority_queue<PII> PQII;

const double EPS = 1e-10;
const ll mod = 1000000007;
int n;
ll dp[2][2][3][2][8];

ll calc(string s, int p, int less) {
  int pn = -1;  //pn...8:0, 80:1, 800:2
  while (p) {
    pn++;
    p /= 10;
  }

  n = (int)s.size();
  memset(dp, 0, sizeof(dp));
  dp[0][0][0][0][0] = 1;
  ll minus = 0; //in case of 80, 800
  int crt, nxt;
  REP(i,n) {
    crt = i&1; nxt = (i+1)&1;

    REP(j,2) REP(k,3) REP(l,2) {
      int lim = j ? 9 : s[i]-'0';

      if (i<n-3-pn) {
        ll x = dp[crt][j][k][l][0];
        REP(d,lim+1) (dp[nxt][j || d<lim][(k*10+d)%3][l || d==3][0] += x) %= mod;
      } else {
        REP(m,8) {
          ll x = dp[crt][j][k][l][m];
          if (pn && i+pn==n && (!k || l) && !m) (minus += x) %= mod;
          REP(d,lim+1) (dp[nxt][j || d<lim][(k*10+d)%3][l || d==3][(m*10+d)%8] += x) %= mod;
        }
      }
    }

    memset(dp[crt], 0, sizeof(dp[crt]));
  } 

  ll res = 0;
  REP(j,2) REP(k,3) REP(l,2) REP(m,8) {
    if (less && !j) continue; //[0,a)
    if (!pn && !m) continue;  //pn==0
    if (!k || l) (res += dp[nxt][j][k][l][m]) %= mod;
  }

  return (res + mod - minus)%mod;
}

int main() {
  string a, b;
  int p;
  cin >> a >> b >> p;
  printf("%lld\n", (calc(b,p,0)+mod-calc(a,p,1))%mod);
  return 0;
}
0