結果
| 問題 |
No.260 世界のなんとか3
|
| コンテスト | |
| ユーザー |
purple_jwl
|
| 提出日時 | 2016-07-13 21:50:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,805 bytes |
| コンパイル時間 | 1,357 ms |
| コンパイル使用メモリ | 162,964 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-10-14 15:44:23 |
| 合計ジャッジ時間 | 3,029 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 14 |
ソースコード
#include <bits/stdc++.h>
#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll MOD = 1e9 + 7;
ll dp[10000 + 5][2][2][3][8]; // dp[桁][未満][3を含む][mod 3][mod 8]
ll func(string s) {
memset(dp, 0, sizeof(dp));
dp[0][0][0][0][0] = 1;
rep (i, sz(s)) rep (j, 2) {
int d = j ? 9 : s[i] - '0';
rep (k, d + 1) rep (p, 2) rep (q, 3) rep (r, 8) {
dp[i + 1][j | (int)(k < d)][p | (int)(k == 3)][(q + k) % 3][(r * 10 + k) % 8] += dp[i][j][p][q][r];
dp[i + 1][j | (int)(k < d)][p | (int)(k == 3)][(q + k) % 3][(r * 10 + k) % 8] %= MOD;
}
}
ll ans = 0;
rep (j, 2) rep (k, 2) rep (p, 3) rep (q, 8) {
if ((k == 1 || p == 0) && q != 0) {
ans += dp[sz(s)][j][k][p][q];
ans %= MOD;
}
}
return ans;
}
string decrement(string s) {
reverse(all(s));
vector<int> tmp;
rep (i, sz(s)) {
tmp.eb(s[i] - '0');
}
tmp[0]--;
string res = "";
rep (i, sz(tmp)) {
if (tmp[i] < 0) {
tmp[i] += 10;
tmp[i + 1]--;
}
res += (char)(tmp[i] + '0');
}
if (sz(res) > 1 && res.back() == '0') {
res.pop_back();
}
reverse(all(res));
return res;
}
int main() {
string A, B;
cin >> A >> B;
cout << func(B) - func(decrement(A)) << endl;
}
purple_jwl