結果
問題 | No.260 世界のなんとか3 |
ユーザー | nomi |
提出日時 | 2019-02-16 16:31:04 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 75 ms / 2,000 ms |
コード長 | 2,824 bytes |
コンパイル時間 | 1,504 ms |
コンパイル使用メモリ | 170,448 KB |
実行使用メモリ | 21,780 KB |
最終ジャッジ日時 | 2024-09-22 13:24:59 |
合計ジャッジ時間 | 3,832 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
20,080 KB |
testcase_01 | AC | 7 ms
20,112 KB |
testcase_02 | AC | 6 ms
20,136 KB |
testcase_03 | AC | 75 ms
21,724 KB |
testcase_04 | AC | 74 ms
21,760 KB |
testcase_05 | AC | 31 ms
20,720 KB |
testcase_06 | AC | 22 ms
20,688 KB |
testcase_07 | AC | 63 ms
21,508 KB |
testcase_08 | AC | 63 ms
21,504 KB |
testcase_09 | AC | 34 ms
20,812 KB |
testcase_10 | AC | 58 ms
21,348 KB |
testcase_11 | AC | 68 ms
21,560 KB |
testcase_12 | AC | 52 ms
21,192 KB |
testcase_13 | AC | 16 ms
20,328 KB |
testcase_14 | AC | 64 ms
21,560 KB |
testcase_15 | AC | 19 ms
20,496 KB |
testcase_16 | AC | 52 ms
21,344 KB |
testcase_17 | AC | 40 ms
20,956 KB |
testcase_18 | AC | 36 ms
20,792 KB |
testcase_19 | AC | 65 ms
21,480 KB |
testcase_20 | AC | 42 ms
21,008 KB |
testcase_21 | AC | 44 ms
21,108 KB |
testcase_22 | AC | 54 ms
21,312 KB |
testcase_23 | AC | 11 ms
20,220 KB |
testcase_24 | AC | 59 ms
21,396 KB |
testcase_25 | AC | 74 ms
21,780 KB |
testcase_26 | AC | 71 ms
21,772 KB |
testcase_27 | AC | 7 ms
20,012 KB |
testcase_28 | AC | 8 ms
21,780 KB |
testcase_29 | AC | 9 ms
21,676 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long #define vvi vector<vector<int>> #define vec vector #define pq priority_queue #define all(v) (v).begin(), (v).end() #define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); #define rep(i, n) for (int (i) = (0); (i) < (n); ++(i)) #define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i)) #define dbg(x) cerr << #x << ": " << x << endl; #define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl; #define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl; #define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl; #define line() cerr << "---------------" << endl; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const double PI = 3.14159265358979323846; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } template<typename T> void print1(T begin, T end) { while (begin != end) { cout << (*begin) << " "; *begin++; } cout << endl; } template<typename T> void print2(T Array, int height, int width) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { cout << " " << Array[i][j]; } cout << endl; } } void print() { std::cerr << endl; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { std::cerr << head << " "; print(std::forward<Tail>(tail)...); } template<class T> void Add(T &a, const T &b, const T &mod=1000000007) { int val = ((a % mod) + (b % mod)) % mod; if (val < 0) { val += mod; } a = val; } // ------------------------------------------------------------------------------------------ string A, B; int dp[11111][2][2][2][3][8]; int a[111]; int rec(int digit, int over, int smaller, int three, int mod3, int mod8) { if (digit >= B.size()) { return (three || mod3 == 0) && (mod8 != 0); } if (dp[digit][over][smaller][three][mod3][mod8] != -1) { return dp[digit][over][smaller][three][mod3][mod8]; } int ue = (smaller ? 9 : B[digit] - '0'); int shita = (over ? 0 : A[digit] - '0'); int ret = 0; for (int num = shita; num <= ue; num++) { int t = rec(digit+1, over || (num > shita), smaller || (num < ue), three || (num == 3), (mod3+num)%3, (10*mod8+num)%8); Add(ret, t); } return dp[digit][over][smaller][three][mod3][mod8] = ret; } signed main() { cin >> A >> B; int diff = B.size() - A.size(); string zero = ""; rep (i, diff) { zero += "0"; } A = zero + A; rep (i, 11111) rep (j, 2) rep (k, 2) rep (l, 2) rep (m, 3) rep (n, 8) dp[i][j][k][l][m][n] = -1; int ans = rec(0, 0, 0, 0, 0, 0); cout << ans << endl; return 0; }