結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー tnakao0123tnakao0123
提出日時 2021-03-13 01:01:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,565 bytes
コンパイル時間 983 ms
コンパイル使用メモリ 94,852 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 15:51:32
合計ジャッジ時間 2,037 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 = 10000;
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 cj2 = 0, cj5 = 0;

  seti(1, 0, 0, 1, s[0] - '0');
  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';
    seti(i + 1, cj2, cj5, 1, si);
    cj2 = min(2, cj2 + d2s[si]);
    cj5 = min(2, cj5 + d5s[si]);
  }

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

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