結果
問題 | No.1417 100の倍数かつ正整数(2) |
ユーザー |
![]() |
提出日時 | 2024-11-05 13:36:47 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 47 ms / 3,000 ms |
コード長 | 1,209 bytes |
コンパイル時間 | 2,629 ms |
コンパイル使用メモリ | 217,300 KB |
実行使用メモリ | 16,000 KB |
最終ジャッジ日時 | 2024-11-05 13:36:51 |
合計ジャッジ時間 | 4,354 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios_base::sync_with_stdio(false);cin.tie(nullptr);}#include <atcoder/modint>using mint = atcoder::modint1000000007;int main() {fast_io();string N;cin >> N;vector<int> n;for (char c : N) {n.push_back(c - '0');}int m = n.size();vector dp(m + 1, vector(2, vector(3, vector(3, vector<mint>(2)))));dp[0][0][0][0][1] = 1;for (int i = 0; i < m; i++) {for (int smaller = 0; smaller < 2; smaller++) {for (int j2 = 0; j2 < 3; j2++) {for (int j5 = 0; j5 < 3; j5++) {for (int lead_zero = 0; lead_zero < 2; lead_zero++) {for (int x = (lead_zero ? 0 : 1);x <= (smaller ? 9 : n[i]); x++) {int nj2 = j2, nj5 = j5;if (x > 0) {if (x % 4 == 0) {nj2 += 2;} else if (x % 2 == 0) {nj2++;} else if (x % 5 == 0) {nj5++;}}nj2 = min(nj2, 2);nj5 = min(nj5, 2);dp[i + 1][smaller || x < n[i]][nj2][nj5][lead_zero && (x == 0)] +=dp[i][smaller][j2][j5][lead_zero];}}}}}}mint ans = dp[m][0][2][2][0] + dp[m][1][2][2][0];cout << ans.val() << endl;}