結果

問題 No.315 世界のなんとか3.5
ユーザー heno239
提出日時 2020-08-26 17:47:12
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,090 ms / 2,000 ms
コード長 5,004 bytes
コンパイル時間 1,273 ms
コンパイル使用メモリ 119,848 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-07 13:15:18
合計ジャッジ時間 15,398 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);
ll mod_pow(ll x, ll n, ll m) {
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() :n(0) { ; }
modint(ll m) :n(m) {
if (n >= mod)n %= mod;
else if (n < 0)n = (n % mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 1;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
struct uf {
private:
vector<int> par;
vector<vector<int>> ids;
vector<int> col;
public:
uf(int n) {
par.resize(n, 0);
ids.resize(n);
col.resize(n, 0);
rep(i, n) {
ids[i].push_back(i);
par[i] = i;
}
}
int find(int x) {
if (par[x] == x)return x;
else return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)return;
par[y] = x;
for (int id : ids[y])ids[x].push_back(id);
ids[y].clear();
ids[y].shrink_to_fit();
}
void nuru(int x, int c) {
col[find(x)] = c;
}
int takecol(int x) {
return col[find(x)];
}
bool same(int x, int y) {
return find(x) == find(y);
}
vector<int> takeall(int x) {
return ids[find(x)];
}
void eraseorigin(int x,int sz) {
int p = find(x);
ids[p].erase(ids[p].begin(), ids[p].begin() + sz);
}
};
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int p;
//mod 24,3,S
modint dp[24][2][2];
modint cop[24][2][2];
modint calc(string s) {
rep(i, 24)rep(j, 2)rep(k, 2)dp[i][j][k] = 0;
dp[0][0][0] = 1;
int len = s.size();
rep(i, len - 2) {
rep(j, 24)rep(k, 2)rep(l, 2)cop[j][k][l] = 0;
int z = s[i] - '0';
rep(j, 24)rep(k, 2)rep(l, 2)rep(t, 10) {
if (l == 0 && t > z)continue;
int nj = (10 * j + t) % 24;
int nk = k; if (t == 3)nk = 1;
int nl = l; if (t < z)nl = 1;
cop[nj][nk][nl] += dp[j][k][l];
}
rep(j, 24)rep(k, 2)rep(l, 2)dp[j][k][l] = cop[j][k][l];
}
int x = s.back() - '0';
if (len >= 2) {
x += 10 * (s[len - 2] - '0');
}
modint ans = 0;
rep(j, 24)rep(k, 2)rep(l, 2) {
rep(las, 100) {
if (l == 0 && x < las)continue;
int u = j * 100 + las;
if (u % p == 0)continue;
bool aho = false;
if (u % 3 == 0)aho = true;
if (u % 10 == 3)aho = true;
if (u % 100 - u % 10 == 30)aho = true;
if (k)aho = true;
if (aho) {
//if(dp[j][k][l]!=(modint)0)cout << "/ " << j<<" "<<las << "\n";
ans += dp[j][k][l];
}
}
}
return ans;
}
void solve() {
string a, b; cin >> a >> b >> p;
//cout << calc(b) << "\n";
modint ans = calc(b) - calc(a);
bool exi3 = false;
for (char c : a)if (c == '3')exi3 = true;
int cur = 0;
rep(i, a.size()) {
cur = (10 * cur + a[i] - '0') % (3 * p);
}
if (cur % p && (cur % 3 == 0 || exi3))ans += 1;
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed << setprecision(15);
//init_f();
//expr();
//int t; cin >> t; rep(i, t)
solve();
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0