結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー tnakao0123tnakao0123
提出日時 2021-03-13 01:29:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 3,000 ms
コード長 1,671 bytes
コンパイル時間 859 ms
コンパイル使用メモリ 92,888 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-04 17:55:27
合計ジャッジ時間 2,329 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1417.cc:  No.1417 100の倍数かつ正整数(2) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_L = 10001;
const int MOD = 1000000007;

const int d2s[] = { 0, 0, 1, 0, 2, 0, 1, 0, 2, 0 };
const int d5s[] = { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 };

/* typedef */

typedef long long ll;

/* global variables */

char s[MAX_L + 4];
int dp[MAX_L + 1][3][3];

/* subroutines */

inline void addmod(int &a, int b) { a = (a + b) % MOD; }
inline int pmod(int a, int b) { return (ll)a * b % MOD; }

void seti(int i, int j2, int j5, int d0, int maxk) {
  for (int k = 1; k < maxk; k++)
    addmod(dp[i][min(2, j2 + d2s[k])][min(2, j5 + d5s[k])], d0);
}

/* main */

int main() {
  scanf("%s", s);
  int l = strlen(s);

  int s0 = s[0] - '0';
  seti(1, 0, 0, 1, s0);
  int cj2 = d2s[s0], cj5 = d5s[s0];
  bool z = false;

  for (int i = 1; i < l; i++) {
    for (int j2 = 0; j2 <= 2; j2++)
      for (int j5 = 0; j5 <= 2; j5++) {
	int d0 = dp[i][j2][j5];
	if (d0 > 0) seti(i + 1, j2, j5, d0, 10);
      }

    seti(i + 1, 0, 0, 1, 10);

    int si = s[i] - '0';
    if (si == 0) z = true;
    if (! z) {
      seti(i + 1, cj2, cj5, 1, si);
      cj2 = min(2, cj2 + d2s[si]);
      cj5 = min(2, cj5 + d5s[si]);
    }
  }

  if (! z && cj2 == 2 && cj5 == 2) addmod(dp[l][2][2], 1);

  printf("%d\n", dp[l][2][2]);
  return 0;
}
0