結果

問題 No.315 世界のなんとか3.5
ユーザー kyawashellkyawashell
提出日時 2018-03-26 13:58:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,952 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 202,944 KB
実行使用メモリ 8,048 KB
最終ジャッジ日時 2023-09-07 12:41:23
合計ジャッジ時間 10,935 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll mod = 1e9+7;
string A,B;
ll P;
ll dp [2][2][2][3][800];
int main(){
	cin >> A >> B >> P;


	ll n = B.length();

	dp[0][0][0][0][0] = 1;

	REP(i,n) {
		REP(j,2) {
			REP(k,2) {
				REP(l,3) {
					REP(m,P) {
						ll lim = (j ? 9 : B[i] - '0');

						REP(d,lim + 1) {
							(dp[1][j || d < lim][k || d == 3][(10 * l + d) % 3][(10 * m + d) % P] += dp[0][j][k][l][m] ) %= mod;
						}
					}
				}
			}
		}
		REP(j,2) {
			REP(k,2) {
				REP(l,3) {
					REP(m,P) {
						dp[0][j][k][l][m] = dp[1][j][k][l][m];
						dp[1][j][k][l][m] = 0;
					}
				}
			}
		}
	}

	ll ans = 0;
	REP(j,2) {
		REP(k,2) {
			REP(l,3) {
				REP(m,P) {
					if((k || !l) && m) {
						(ans += dp[0][j][k][l][m]) %= mod;
					}
				}
			}
		}
	}

	n = A.length();
	REP(i,2) {
		REP(j,2) {
			REP(k,2) {
				REP(l,3) {
					REP(m,P) {
						dp[i][j][k][l][m] = 0;
					}
				}
			}
		}
	}

	dp[0][0][0][0][0] = 1;

	REP(i,n) {
		REP(j,2) {
			REP(k,2) {
				REP(l,3) {
					REP(m,P) {
						ll lim = (j ? 9 : A[i] - '0');

						REP(d,lim + 1) {
							(dp[1][j || d < lim][k || d == 3][(10 * l + d) % 3][(10 * m + d) % P] += dp[0][j][k][l][m] ) %= mod;
						}
					}
				}
			}
		}
		REP(j,2) {
			REP(k,2) {
				REP(l,3) {
					REP(m,P) {
						dp[0][j][k][l][m] = dp[1][j][k][l][m];
						dp[1][j][k][l][m] = 0;
					}
				}
			}
		}
		
	}

	
	REP(j,2) {
		REP(k,2) {
			REP(l,3) {
				REP(m,P) {
					if(j && (k || !l) && m) {
						(ans += mod - dp[0][j][k][l][m]) %= mod;
					}
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}
0