結果

問題 No.260 世界のなんとか3
ユーザー alumina_8alumina_8
提出日時 2019-03-29 14:58:54
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,965 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 83,824 KB
実行使用メモリ 20,532 KB
最終ジャッジ日時 2023-08-20 12:08:08
合計ジャッジ時間 2,617 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,020 KB
testcase_01 AC 1 ms
4,956 KB
testcase_02 AC 1 ms
4,892 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
4,888 KB
testcase_28 AC 69 ms
18,472 KB
testcase_29 AC 83 ms
18,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
constexpr long long int mod = 1000000007;

using namespace std;

string A,B;
long long int dp1[100001][2][2][3][8],dp2[100001][2][2][3][8];

int main() {
    cin >> A>>B;
    int n = A.size(),p=B.size();
    dp1[0][0][0][0][0] = 1;
    dp2[0][0][0][0][0] = 1;
    int tmp = n - 1;
    while(A[tmp]=='0'){
        A[tmp] = '9';
        tmp--;
    }
    A[tmp]--;
    if(A[0]=='0'){
        A = A.substr(1);
        n--;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                for (int l = 0; l < 3; l++) {
                    for (int m = 0; m < 8; m++) {
                        int x = j ? 9 : A[i] - '0';
                        for (int d = 0; d <= x; d++) {
                            dp1[i + 1][j || d < x][k || d == 3][(l + d) % 3][(m * 10 + d) % 8] += dp1[i][j][k][l][m];
                        }
                    }
                }
            }
        }
    }
    for (int i = 0; i < p; i++){
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                for (int l = 0; l < 3; l++) {
                    for (int m = 0; m < 8; m++) {
                        int x = j ? 9 : B[i] - '0';
                        for (int d = 0; d <= x; d++) {
                            dp2[i + 1][j || d < x][k || d == 3][(l + d) % 3][(m * 10 + d) % 8] += dp2[i][j][k][l][m];
                        }
                    }
                }
            }
        }
    }
    long long int ans = 0;
    for (int j = 0; j < 2; j++) {
        for (int k = 0; k < 2; k++) {
            for (int l = 0; l < 3; l++) {
                for (int m = 0; m < 8; m++) {
                    if ((k || l == 0) && m != 0) {
                        ans -= dp1[n][j][k][l][m]-dp2[p][j][k][l][m];
                        ans %= mod;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}
0